diff --git a/addons/account/data/account_data.xml b/addons/account/data/account_data.xml
index 8a740219064..e8899d0348a 100644
--- a/addons/account/data/account_data.xml
+++ b/addons/account/data/account_data.xml
@@ -555,19 +555,6 @@
-
+
- Remove information on Account data => because they move on analysis sheet
- create a page with invoicing informations
-
-
- account.analytic.account.invoice.stat.form.inherit
- account.analytic.account
- form
-
-
-
-
-
-
-
-
-
-
- -->
Invoice On Timesheets
-
+
@@ -86,17 +65,7 @@
-
-
Charge Expenses
-
-
-
-
-
-
-
-
-
+
Total
diff --git a/addons/analytic_contract_hr_expense/__init__.py b/addons/analytic_contract_hr_expense/__init__.py
new file mode 100644
index 00000000000..ca4044b0584
--- /dev/null
+++ b/addons/analytic_contract_hr_expense/__init__.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# 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 .
+#
+##############################################################################
+
+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
index 00000000000..53c7ac5804f
--- /dev/null
+++ b/addons/analytic_contract_hr_expense/__openerp__.py
@@ -0,0 +1,47 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# 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 .
+#
+##############################################################################
+
+
+{
+ '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
index 00000000000..87878090777
--- /dev/null
+++ b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense.py
@@ -0,0 +1,155 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL ().
+#
+# 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 .
+#
+##############################################################################
+
+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
index 00000000000..07cc3c7e594
--- /dev/null
+++ b/addons/analytic_contract_hr_expense/analytic_contract_hr_expense_view.xml
@@ -0,0 +1,27 @@
+
+
+
+
+ account.analytic.account.form.expense.inherit
+ account.analytic.account
+ form
+
+
+
+
+