From 1a9393c8d7cef5f06e47ef1c657d3cb6fe037d25 Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Wed, 6 Mar 2019 08:58:52 +0000 Subject: [PATCH] [FIX] account: invoice compute tax group amount correctly grouped Before this commit, when printing an invoice, the taxes were grouped by their tax group (NOT by their parent tax) Summing the base of each tax in the process. This was largely insufficient, as tax groups can have taxes with different rates or computation method within them The summing of the base of each tax for reach tax group was in this case plain wrong This commit aims at grouping by group > computation method > amount Which makes more sense OPW 1947202 OPW 1945353 closes odoo/odoo#31617 Signed-off-by: Lucas Perais (lpe) --- addons/account/models/account_invoice.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 5c5ee899d7c..2ecf172c8c9 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -1559,12 +1559,14 @@ class AccountInvoice(models.Model): fmt = partial(formatLang, invoice.with_context(lang=invoice.partner_id.lang).env, currency_obj=currency) res = {} for line in invoice.tax_line_ids: - res.setdefault(line.tax_id.tax_group_id, {'base': 0.0, 'amount': 0.0}) - res[line.tax_id.tax_group_id]['amount'] += line.amount_total - res[line.tax_id.tax_group_id]['base'] += line.base - res = sorted(res.items(), key=lambda l: l[0].sequence) + tax = line.tax_id + group_key = (tax.tax_group_id, tax.amount_type, tax.amount) + res.setdefault(group_key, {'base': 0.0, 'amount': 0.0}) + res[group_key]['amount'] += line.amount_total + res[group_key]['base'] += line.base + res = sorted(res.items(), key=lambda l: l[0][0].sequence) invoice.amount_by_group = [( - r[0].name, r[1]['amount'], r[1]['base'], + r[0][0].name, r[1]['amount'], r[1]['base'], fmt(r[1]['amount']), fmt(r[1]['base']), len(res), ) for r in res]