From 34706433e7483a2e2b80e4285be06102c9268ed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Fri, 6 Jun 2014 16:51:09 +0200 Subject: [PATCH 1/2] [FIX] Error when manually adding analytic account in the generated tax lines on an invoice fixes #374 fixes https://bugs.launchpad.net/ocb-addons/+bug/1084822 The fix considers invoice tax lines with different analytic account are equivalent for the purpose of checking if the list of tax line is complete. Caveat, this changes the structure of keys in the dictionary returned by account.invoice.tax's compute method, I suppose this is ok for the master branch. --- addons/account/account_invoice.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 455feb14afb..31dc846fb77 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -712,7 +712,7 @@ class account_invoice(models.Model): for tax in self.tax_line: if tax.manual: continue - key = (tax.tax_code_id.id, tax.base_code_id.id, tax.account_id.id, tax.account_analytic_id.id) + key = (tax.tax_code_id.id, tax.base_code_id.id, tax.account_id.id) tax_key.append(key) if key not in compute_taxes: raise except_orm(_('Warning!'), _('Global taxes defined, but they are not in invoice lines !')) @@ -1549,7 +1549,7 @@ class account_invoice_tax(models.Model): val['account_id'] = tax['account_paid_id'] or line.account_id.id val['account_analytic_id'] = tax['account_analytic_paid_id'] - key = (val['tax_code_id'], val['base_code_id'], val['account_id'], val['account_analytic_id']) + key = (val['tax_code_id'], val['base_code_id'], val['account_id']) if not key in tax_grouped: tax_grouped[key] = val else: From 12a39db8c3ac5741f7b52d40c94b81f1e51c6dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Mon, 23 Jun 2014 17:23:32 +0200 Subject: [PATCH 2/2] [FIX] Preserve analytic account on tax lines which are on same general account as invoice line After careful analysis, I'm now convinced it is a good thing to preserve the analytic account on taxes line which have the same general account as the invoice line. This is the best default case and will save time for users, while leaving the flexibility to adapt the analytic account on taxes manually. --- addons/account/account_invoice.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/addons/account/account_invoice.py b/addons/account/account_invoice.py index 31dc846fb77..f9e9ff2813d 100644 --- a/addons/account/account_invoice.py +++ b/addons/account/account_invoice.py @@ -145,7 +145,7 @@ class account_invoice(models.Model): else: self.residual = new_value # prevent the residual amount on the invoice to be less than 0 - self.residual = max(self.residual, 0.0) + self.residual = max(self.residual, 0.0) @api.one @api.depends( @@ -1549,6 +1549,14 @@ class account_invoice_tax(models.Model): val['account_id'] = tax['account_paid_id'] or line.account_id.id val['account_analytic_id'] = tax['account_analytic_paid_id'] + # If the taxes generate moves on the same financial account as the invoice line + # and no default analytic account is defined at the tax level, propagate the + # analytic account from the invoice line to the tax line. This is necessary + # in situations were (part of) the taxes cannot be reclaimed, + # to ensure the tax move is allocated to the proper analytic account. + 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 = (val['tax_code_id'], val['base_code_id'], val['account_id']) if not key in tax_grouped: tax_grouped[key] = val