From fb6a05d358b89fcb1c02ebc242d4b21cfb17fb5f Mon Sep 17 00:00:00 2001 From: qdp-odoo Date: Tue, 5 Jul 2016 09:51:54 +0200 Subject: [PATCH] [FIX] account: fixed grouping of account.invoice.tax creation. in details: [FIX] added analytic account in grouping key of because we need to create different journal items for each of the lines having a different analytic account. [REF] added a function on account.tax that returns the grouping key and that could be inherited in another (community) module --- addons/account/models/account.py | 5 +++++ addons/account/models/account_invoice.py | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/addons/account/models/account.py b/addons/account/models/account.py index 47f4021504d..d0aca4fafe4 100644 --- a/addons/account/models/account.py +++ b/addons/account/models/account.py @@ -602,6 +602,11 @@ class AccountTax(models.Model): if self.price_include: self.include_base_amount = True + def get_grouping_key(self, invoice_tax_val): + """ Returns a string that will be used to group account.invoice.tax sharing the same properties""" + self.ensure_one() + return str(invoice_tax_val['tax_id']) + '-' + str(invoice_tax_val['account_id']) + '-' + str(invoice_tax_val['account_analytic_id']) + def _compute_amount(self, base_amount, price_unit, quantity=1.0, product=None, partner=None): """ Returns the amount of a single tax. base_amount is the actual amount on which the tax is applied, which is price_unit * quantity eventually affected by previous taxes (if tax is include_base_amount XOR price_include) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 3ac033834f8..8c0f643bc6f 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -567,7 +567,8 @@ class AccountInvoice(models.Model): if not val.get('account_analytic_id') and line.account_analytic_id and val['account_id'] == line.account_id.id: val['account_analytic_id'] = line.account_analytic_id.id - key = str(tax['id']) + '-' + str(val['account_id']) + key = self.env['account.tax'].browse(tax['id']).get_grouping_key(val) + if key not in tax_grouped: tax_grouped[key] = val else: