[ADD] analytic_contract_hr_expense: split of features of account_analytic_analysis...
authorQuentin (OpenERP) <qdp-launchpad@openerp.com>
Thu, 7 Jun 2012 12:36:41 +0000 (14:36 +0200)
committerQuentin (OpenERP) <qdp-launchpad@openerp.com>
Thu, 7 Jun 2012 12:36:41 +0000 (14:36 +0200)
bzr revid: qdp-launchpad@openerp.com-20120607123641-kjzynx1wwi4282lu

addons/account/data/account_data.xml
addons/account_analytic_analysis/__openerp__.py
addons/account_analytic_analysis/account_analytic_analysis.py
addons/account_analytic_analysis/account_analytic_analysis_view.xml
addons/analytic_contract_hr_expense/__init__.py [new file with mode: 0644]
addons/analytic_contract_hr_expense/__openerp__.py [new file with mode: 0644]
addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py [new file with mode: 0644]
addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml [new file with mode: 0644]

index 8a74021..e8899d0 100644 (file)
             <field eval="1" name="number_increment"/>
         </record>
 
-        <!-- 
-        Sequence for analytic account 
-        
-        <record id="seq_type_analytic_account" model="ir.sequence.type">
-            <field name="name">Analytic account</field>
-            <field name="code">account.analytic.account</field>
-        </record>
-        <record id="seq_analytic_account" model="ir.sequence">
-            <field name="name">Analytic account sequence</field>
-            <field name="code">account.analytic.account</field>
-            <field eval="3" name="padding"/>
-            <field eval="2708" name="number_next"/>
-        </record>-->
 
         <!--
         Invoice requests (deprecated)
index 164eb8b..abb399f 100644 (file)
@@ -35,7 +35,7 @@ user-wise as well as month wise.
     "author": "Camptocamp",
     "website": "http://www.camptocamp.com/",
     "images": ["images/bill_tasks_works.jpeg","images/overpassed_accounts.jpeg"],
-    "depends": ["hr_expense","hr_timesheet_invoice", "sale","project"], #although sale is technically not required to install this module, all menuitems are located under 'Sales' application
+    "depends": ["hr_timesheet_invoice", "sale","project"], #although sale is technically not required to install this module, all menuitems are located under 'Sales' application
     "init_xml": [],
     "update_xml": [
                     "security/ir.model.access.csv",
index 4e1e427..76aba53 100644 (file)
@@ -224,51 +224,7 @@ class account_analytic_account(osv.osv):
                 res[account_id] = round(sum,2)
         res_final = res
         return res_final
-    
-    def _expense_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
-        res = {}
-        res_final = {}
-        child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
-        for i in child_ids:
-            res[i] =  0.0
-        if not child_ids:
-            return res
 
-        if child_ids:
-            cr.execute("SELECT hel.analytic_account,SUM(hel.unit_amount*hel.unit_quantity)\
-                    FROM hr_expense_line AS hel\
-                    LEFT JOIN hr_expense_expense AS he \
-                        ON he.id = hel.expense_id\
-                    WHERE he.state = 'paid' \
-                         AND hel.analytic_account IN %s \
-                    GROUP BY hel.analytic_account",(child_ids,))
-            for account_id, sum in cr.fetchall():
-                res[account_id] = sum
-        res_final = res
-        return res_final
-    
-    def _expense_to_invoice_calc(self, cr, uid, ids, name, arg, context=None):
-        res = {}
-        res_final = {}
-        child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
-        for i in child_ids:
-            res[i] =  0.0
-        if not child_ids:
-            return res
-
-        if child_ids:
-            cr.execute("SELECT hel.analytic_account, SUM(hel.unit_amount*hel.unit_quantity) \
-                    FROM hr_expense_line AS hel\
-                    LEFT JOIN hr_expense_expense AS he \
-                        ON he.id = hel.expense_id\
-                    WHERE he.state = 'invoiced' \
-                        AND hel.analytic_account IN %s \
-                    GROUP BY hel.analytic_account",(child_ids,))
-            for account_id, sum in cr.fetchall():
-                res[account_id] = sum
-        res_final = res
-        return res_final
-    
     def _total_cost_calc(self, cr, uid, ids, name, arg, context=None):
         res = {}
         res_final = {}
@@ -345,17 +301,6 @@ class account_analytic_account(osv.osv):
         for id in ids:
             res[id] = round(res.get(id, 0.0),2)
         return res
-    
-    def _remaining_expnse_calc(self, cr, uid, ids, name, arg, context=None):
-        res = {}
-        for account in self.browse(cr, uid, ids, context=context):
-            if account.expense_max != 0:
-                res[account.id] = account.expense_max - account.expense_invoiced
-            else:
-                res[account.id]=0.0
-        for id in ids:
-            res[id] = round(res.get(id, 0.0),2)
-        return res
 
     def _real_margin_calc(self, cr, uid, ids, name, arg, context=None):
         res = {}
@@ -387,33 +332,46 @@ class account_analytic_account(osv.osv):
         for line in self.pool.get('account.analytic.line').browse(cr, uid, ids, context=context):
             result.add(line.account_id.id)
         return list(result)
-    
+
+    def _get_total_estimation(self, account):
+        tot_est = 0.0
+        if account.fix_price_invoices:
+            total_est += account.amount_max 
+        if account.invoice_on_timesheets:
+            tot_est += account.hours_qtt_est
+        return tot_est
+
+    def _get_total_invoiced(self, account):
+        total_invoiced = 0.0
+        if account.fix_price_invoices:
+            total_invoiced += account.ca_invoiced
+        if account.invoice_on_timesheets:
+            total_invoiced += account.hours_qtt_invoiced
+        return total_invoiced
+
+    def _get_total_remaining(self, account):
+        total_remaining = 0.0
+        if account.fix_price_invoices:
+            total_remaining += account.remaining_ca
+        if account.invoice_on_timesheets:
+            total_remaining += account.remaining_hours
+        return total_remaining
+
+    def _get_total_toinvoice(self, account):
+        total_toinvoice = 0.0
+        if account.fix_price_invoices:
+            total_toinvoice += account.ca_to_invoice
+        if account.invoice_on_timesheets:
+            total_toinvoice += account.hours_qtt_non_invoiced
+        return total_toinvoice
+
     def _sum_of_fields(self, cr, uid, ids, name, arg, context=None):
          res = dict([(i, {}) for i in ids])
-         total_max = 0.0
-         total_invoiced = 0.0
-         total_toinvoice = 0.0
-         total_remaining = 0.0
          for account in self.browse(cr, uid, ids, context=context):
-            if account.fix_price_invoices:
-                total_max += account.amount_max 
-                total_invoiced += account.ca_invoiced
-                total_remaining += account.remaining_ca
-                total_toinvoice += account.ca_to_invoice
-            if account.invoice_on_timesheets:
-                total_max += account.quantity_max 
-                total_invoiced += account.hours_qtt_invoiced
-                total_remaining += account.remaining_hours
-                total_toinvoice += account.hours_qtt_non_invoiced
-            if account.charge_expenses:
-                total_max += account.expense_max 
-                total_invoiced += account.expense_invoiced
-                total_remaining += account.remaining_expense
-                total_toinvoice += account.expense_to_invoice
-            res[account.id]['est_total'] = total_max or 0.0
-            res[account.id]['invoiced_total'] =  total_invoiced or 0.0
-            res[account.id]['remaining_total'] = total_remaining or 0.0
-            res[account.id]['toinvoice_total'] =  total_toinvoice or 0.0
+            res[account.id]['est_total'] = self._get_total_estimation(account)
+            res[account.id]['invoiced_total'] =  self._get_total_invoiced(account)
+            res[account.id]['remaining_total'] = self._get_total_remaining(account)
+            res[account.id]['toinvoice_total'] =  self._get_total_toinvoice(account)
          return res
 
     _columns = {
@@ -464,21 +422,16 @@ class account_analytic_account(osv.osv):
             digits_compute=dp.get_precision('Account')),
         'fix_price_invoices' : fields.boolean('Fix Price Invoices'),
         'invoice_on_timesheets' : fields.boolean("Invoice On Timesheets"),
-        'charge_expenses' : fields.boolean('Charge Expenses'),
         'month_ids': fields.function(_analysis_all, multi='analytic_analysis', type='many2many', relation='account_analytic_analysis.summary.month', string='Month'),
         'user_ids': fields.function(_analysis_all, multi='analytic_analysis', type="many2many", relation='account_analytic_analysis.summary.user', string='User'),
         'template_id':fields.many2one('account.analytic.account', 'Template of Contract'),
-        'expense_invoiced' : fields.function(_expense_invoiced_calc, type="float"),
-        'expense_to_invoice' : fields.function(_expense_to_invoice_calc, type='float'),
-        'remaining_expense' : fields.function(_remaining_expnse_calc, type="float"), 
-        #'fix_exp_max' : fields.float('Max. amt'),
-        #'timesheet_max': fields.float('max_timesheet'),
-        'expense_max': fields.float('expenses'),
+        'hours_qtt_est': fields.float('Estimation of Hours to Invoice'),
         'est_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
         'invoiced_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
         'remaining_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
         'toinvoice_total' : fields.function(_sum_of_fields, type="float",multi="sum_of_all"),
     }
+
     def on_change_template(self, cr, uid, id, template_id):
         if not template_id:
             return {}
@@ -500,39 +453,6 @@ class account_analytic_account(osv.osv):
         res['value']['description'] = template.description
         return res
 
-    def open_hr_expense(self, cr, uid, ids, context=None):
-        account = self.browse(cr, uid, ids[0], context)
-        data_obj = self.pool.get('ir.model.data')
-        try:
-            journal_id = data_obj.get_object(cr, uid, 'hr_timesheet', 'analytic_journal').id
-        except ValueError:
-            journal_id = False
-        line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account','=',account.id)])
-        id2 = data_obj._get_id(cr, uid, 'hr_expense', 'view_expenses_form')
-        id3 = data_obj._get_id(cr, uid, 'hr_expense', 'view_expenses_tree')
-        if id2:
-            id2 = data_obj.browse(cr, uid, id2, context=context).res_id
-        if id3:
-            id3 = data_obj.browse(cr, uid, id3, context=context).res_id
-        domain = [('line_ids','in',line_ids)]
-        return {
-            'type': 'ir.actions.act_window',
-            'name': _('Expenses'),
-            'view_type': 'form',
-            'view_mode': 'tree,form',
-            'views': [(id3,'tree'),(id2,'form')],
-            'domain' : domain,
-            'res_model': 'hr.expense.expense',
-            'nodestroy': True,
-        }
-    
-    def hr_to_invoiced_expense(self, cr, uid, ids, context=None):
-         res = self.open_hr_expense(cr,uid,ids,context)
-         account = self.browse(cr, uid, ids[0], context)
-         line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account','=',account.id)])
-         res['domain'] = [('line_ids','in',line_ids),('state','=','invoiced')]
-         return res
-
 account_analytic_account()
 
 class account_analytic_account_summary_user(osv.osv):
index 8d88852..bf45121 100644 (file)
@@ -4,30 +4,9 @@
 
         <!--
         Analytic Account form
+        -->
+
 
-        Remove information on Account data => because they move on analysis sheet
-        create a page with invoicing informations
-       
-        <record id="account_analytic_account_invoice_stat_form" model="ir.ui.view">
-            <field name="name">account.analytic.account.invoice.stat.form.inherit</field>
-            <field name="model">account.analytic.account</field>
-            <field name="type">form</field>
-            <field name="inherit_id" ref="hr_timesheet_invoice.account_analytic_account_form_form"/>
-            <field eval="18" name="priority"/>
-            <field name="arch" type="xml">
-                <group name="invoice_stats" position="inside">
-                    <field name="hours_qtt_non_invoiced" attrs="{'invisible': [('to_invoice','=',0)]}"/>
-                    <field name="ca_to_invoice" attrs="{'invisible': [('to_invoice','=',0)]}"/>
-                    <label string="" colspan="1"/>
-                    <button
-                        name="%(hr_timesheet_invoice.action_hr_timesheet_invoice_create_final)d"
-                        string="Create Invoice"
-                        type="action"
-                        attrs="{'readonly':[('ca_to_invoice','=',0.0)], 'invisible': [('to_invoice','=',0)]}"
-                        icon="gtk-go-forward"/>
-                </group>
-            </field>
-        </record> -->
         <act_window
             id="action_sales_order_line"
             name="Sales Order Lines"
@@ -78,7 +57,7 @@
                         <tr>
                            <th class="oe_border_right">Invoice On Timesheets</th>
                            <td><field name="invoice_on_timesheets" nolabel="1"/></td>
-                           <td><field class="oe_th_110px" name="quantity_max" nolabel="1" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
+                           <td><field class="oe_th_110px" name="hours_qtt_est" nolabel="1" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
                            <td class="oe_th_110px"><field name="hours_qtt_invoiced" nolabel="1" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
                            <td class="oe_th_110px oe_border_right"><field name="remaining_hours" nolabel="1" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
                            <td class="oe_th_110px"><field name="hours_qtt_non_invoiced" nolabel="1" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
                            <td><button class= "oe_btn_width" name="%(hr_timesheet.act_hr_timesheet_line_evry1_all_form)d" string="Timesheets" type="action" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
                            <td><button class= "oe_btn_width" name="%(hr_timesheet_invoice.act_acc_analytic_acc_2_report_acc_analytic_line_to_invoice)d" string="Invoice Timesheets" type="action" attrs="{'invisible': [('invoice_on_timesheets','=',0)]}"/></td>
                         </tr>
-                        <tr>
-                           <th class="oe_border_right">Charge Expenses</th>
-                           <td><field name="charge_expenses" nolabel="1"/></td>
-                           <td><field class="oe_th_110px" name="expense_max" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
-                           <td class="oe_th_110px"><field name="expense_invoiced" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
-                           <td class="oe_th_110px oe_border_right"><field name="remaining_expense" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
-                           <td class="oe_th_110px"><field name="expense_to_invoice" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
-                           <td width="10px"></td>
-                           <td><button class= "oe_btn_width" name="open_hr_expense" string="Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
-                           <td><button class= "oe_btn_width" name="hr_to_invoiced_expense" string="Invoice Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
-                        </tr>
+                        <div name="end_of_tabl_hook"/>
                         <tr>
                            <th class="oe_border_right">Total</th>
                            <td width="10px"></td>
diff --git a/addons/analytic_contract_hr_expense/__init__.py b/addons/analytic_contract_hr_expense/__init__.py
new file mode 100644 (file)
index 0000000..ca4044b
--- /dev/null
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#    
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.     
+#
+##############################################################################
+
+import analytic_contract_hr_expense
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/analytic_contract_hr_expense/__openerp__.py b/addons/analytic_contract_hr_expense/__openerp__.py
new file mode 100644 (file)
index 0000000..53c7ac5
--- /dev/null
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+
+{
+    'name': 'Contracts Management',
+    'version': '1.1',
+    'category': 'Sales Management',
+    'description': """
+This module is for modifying account analytic view to show some data related to the hr_expense module.
+======================================================================================================
+
+""",
+    "author": "OpenERP S.A.",
+    "website": "http://www.openerp.com/",
+    "depends": ["hr_expense","account_analytic_analysis"],
+    "init_xml": [],
+    "update_xml": [
+                    "analytic_contract_hr_expense_view.xml",
+                    ],
+    'demo_xml': [],
+    "css" : [
+             ],
+    'installable': True,
+    'auto_install': True,
+    'certificate': '',
+}
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py
new file mode 100644 (file)
index 0000000..8787809
--- /dev/null
@@ -0,0 +1,155 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
+#
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import osv, fields
+from osv.orm import intersect, except_orm
+import tools.sql
+from tools.translate import _
+from decimal_precision import decimal_precision as dp
+
+
+class account_analytic_account(osv.osv):
+    _name = "account.analytic.account"
+    _inherit = "account.analytic.account"
+
+    def _get_total_estimation(self, account):
+        tot_est = super(account_analytic_account, self)._get_total_estimation(account)
+        if account.charge_expenses:
+            tot_est += account.est_expenses
+        return tot_est
+
+    def _get_total_invoiced(self, account):
+        total_invoiced = super(account_analytic_account, self)._get_total_invoiced(account)
+        if account.charge_expenses:
+            total_invoiced += account.expense_invoiced
+        return total_invoiced
+
+    def _get_total_remaining(self, account):
+        total_remaining = super(account_analytic_account, self)._get_total_remaining(account)
+        if account.charge_expenses:
+            total_remaining += account.remaining_expense
+        return total_remaining
+
+    def _get_total_remaining(self, account):
+        total_toinvoice = super(account_analytic_account, self)._get_total_toinvoice(account)
+        if account.charge_expenses:
+            total_toinvoice += account.expense_to_invoice
+        return total_toinvoice
+
+    def _remaining_expnse_calc(self, cr, uid, ids, name, arg, context=None):
+        res = {}
+        for account in self.browse(cr, uid, ids, context=context):
+            if account.est_expenses != 0:
+                res[account.id] = account.est_expenses - account.expense_invoiced
+            else:
+                res[account.id]=0.0
+        for id in ids:
+            res[id] = round(res.get(id, 0.0),2)
+        return res
+
+    def _expense_to_invoice_calc(self, cr, uid, ids, name, arg, context=None):
+        res = {}
+        res_final = {}
+        child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
+        for i in child_ids:
+            res[i] =  0.0
+        if not child_ids:
+            return res
+
+        if child_ids:
+            cr.execute("SELECT hel.analytic_account, SUM(hel.unit_amount*hel.unit_quantity) \
+                    FROM hr_expense_line AS hel\
+                    LEFT JOIN hr_expense_expense AS he \
+                        ON he.id = hel.expense_id\
+                    WHERE he.state = 'invoiced' \
+                        AND hel.analytic_account IN %s \
+                    GROUP BY hel.analytic_account",(child_ids,))
+            for account_id, sum in cr.fetchall():
+                res[account_id] = sum
+        res_final = res
+        return res_final
+
+    def _expense_invoiced_calc(self, cr, uid, ids, name, arg, context=None):
+        res = {}
+        res_final = {}
+        child_ids = tuple(ids) #We don't want consolidation for each of these fields because those complex computation is resource-greedy.
+        for i in child_ids:
+            res[i] =  0.0
+        if not child_ids:
+            return res
+
+        if child_ids:
+            cr.execute("SELECT hel.analytic_account,SUM(hel.unit_amount*hel.unit_quantity)\
+                    FROM hr_expense_line AS hel\
+                    LEFT JOIN hr_expense_expense AS he \
+                        ON he.id = hel.expense_id\
+                    WHERE he.state = 'paid' \
+                         AND hel.analytic_account IN %s \
+                    GROUP BY hel.analytic_account",(child_ids,))
+            for account_id, sum in cr.fetchall():
+                res[account_id] = sum
+        res_final = res
+        return res_final
+
+    _columns = {
+        'charge_expenses' : fields.boolean('Charge Expenses'),
+        'expense_invoiced' : fields.function(_expense_invoiced_calc, type="float"),
+        'expense_to_invoice' : fields.function(_expense_to_invoice_calc, type='float'),
+        'remaining_expense' : fields.function(_remaining_expnse_calc, type="float"), 
+        'est_expenses': fields.float('Estimation of Expenses to Invoice'),
+    }
+
+    def open_hr_expense(self, cr, uid, ids, context=None):
+        account = self.browse(cr, uid, ids[0], context)
+        data_obj = self.pool.get('ir.model.data')
+        try:
+            journal_id = data_obj.get_object(cr, uid, 'hr_timesheet', 'analytic_journal').id
+        except ValueError:
+            journal_id = False
+        line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account','=',account.id)])
+        id2 = data_obj._get_id(cr, uid, 'hr_expense', 'view_expenses_form')
+        id3 = data_obj._get_id(cr, uid, 'hr_expense', 'view_expenses_tree')
+        if id2:
+            id2 = data_obj.browse(cr, uid, id2, context=context).res_id
+        if id3:
+            id3 = data_obj.browse(cr, uid, id3, context=context).res_id
+        domain = [('line_ids','in',line_ids)]
+        return {
+            'type': 'ir.actions.act_window',
+            'name': _('Expenses'),
+            'view_type': 'form',
+            'view_mode': 'tree,form',
+            'views': [(id3,'tree'),(id2,'form')],
+            'domain' : domain,
+            'res_model': 'hr.expense.expense',
+            'nodestroy': True,
+        }
+
+    def hr_to_invoiced_expense(self, cr, uid, ids, context=None):
+         res = self.open_hr_expense(cr,uid,ids,context)
+         account = self.browse(cr, uid, ids[0], context)
+         line_ids = self.pool.get('hr.expense.line').search(cr,uid,[('analytic_account','=',account.id)])
+         res['domain'] = [('line_ids','in',line_ids),('state','=','invoiced')]
+         return res
+
+account_analytic_account()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
diff --git a/addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml
new file mode 100644 (file)
index 0000000..07cc3c7
--- /dev/null
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<openerp>
+    <data>
+        <record id="account_analytic_account_form_expense_form" model="ir.ui.view">
+            <field name="name">account.analytic.account.form.expense.inherit</field>
+            <field name="model">account.analytic.account</field>
+            <field name="type">form</field>
+            <field name="inherit_id" ref="analytic.view_account_analytic_account_form"/>
+            <field eval="20" name="priority"/>
+            <field name="arch" type="xml">
+                <xpath expr='//div[@name="end_of_tabl_hook"]' position='before'>
+                        <tr>
+                            <th class="oe_border_right">Charge Expenses</th>
+                            <td><field name="charge_expenses" nolabel="1"/></td>
+                            <td><field class="oe_th_110px" name="est_expenses" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
+                            <td class="oe_th_110px"><field name="expense_invoiced" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
+                            <td class="oe_th_110px oe_border_right"><field name="remaining_expense" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
+                            <td class="oe_th_110px"><field name="expense_to_invoice" nolabel="1" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
+                            <td width="10px"></td>
+                            <td><button class= "oe_btn_width" name="open_hr_expense" string="Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
+                            <td><button class= "oe_btn_width" name="hr_to_invoiced_expense" string="Invoice Expenses" type="object" attrs="{'invisible': [('charge_expenses','=',0)]}"/></td>
+                        </tr>
+                </xpath>
+            </field>
+        </record>
+    </data>
+</openerp>