From 7bea91260fe78741962c8105cc57e3c4c5a6efb6 Mon Sep 17 00:00:00 2001
From: "Lucas Perais (lpe)" <lpe@odoo.com>
Date: Thu, 10 Oct 2019 18:34:14 +0000
Subject: [PATCH] [FIX] account: amount by group adapt to repartition

Before this commit, when printing an invoice that has at least
one tax which is part of a tax group and some repartition lines

On the invoice pdf the group of tax contained twice the base amount for that
tax

After this commit, the tax group contains the base only once

OPW 2073989

closes odoo/odoo#37226

Signed-off-by: oco-odoo <oco-odoo@users.noreply.github.com>
---
 addons/account/models/account_invoice.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 90651b8b0a37..d53982e5cb36 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -1776,12 +1776,18 @@ class AccountInvoice(models.Model):
             currency = invoice.currency_id or invoice.company_id.currency_id
             fmt = partial(formatLang, invoice.with_context(lang=invoice.partner_id.lang).env, currency_obj=currency)
             res = {}
+
+            ## There are as many tax line as there are repartition lines
+            done_taxes = set()
             for line in invoice.tax_line_ids:
                 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
+                if tax.id not in done_taxes:
+                    # The base should be added ONCE
+                    res[group_key]['base'] += line.base
+                    done_taxes.add(tax.id)
             res = sorted(res.items(), key=lambda l: l[0][0].sequence)
             invoice.amount_by_group = [(
                 r[0][0].name, r[1]['amount'], r[1]['base'],
-- 
GitLab