From fa2e24c1a295a6f50e4d30c001383c59ca4557ee Mon Sep 17 00:00:00 2001
From: snd <snd@odoo.com>
Date: Mon, 20 Sep 2021 14:50:47 +0000
Subject: [PATCH] [FIX] account_invoice: use tax groups correctly With the
 previous fix, tax groups would not work correctly when checking if a tax
 affected a subsequent tax. With this fix, all taxes that are not of
 amount_type group are aggregated before following the normal flow.

opw-2497281

closes odoo/odoo#76855

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

diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 16883563157d..87956a87ac2c 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -1220,13 +1220,13 @@ class AccountInvoice(models.Model):
                 if tax.include_base_amount:
                     affected_taxes = []
                     for invoice_line in tax_line.invoice_id.invoice_line_ids:
-                        if tax in invoice_line.invoice_line_tax_ids:
-                            following_taxes = invoice_line.invoice_line_tax_ids.filtered(lambda x: x.sequence > tax.sequence
-                                                                                                   or (x.sequence == tax.sequence and x.id > tax.id))
-                            affected_taxes += following_taxes.ids
-                            affected_taxes += following_taxes.mapped('children_tax_ids.id')
+                        if tax in invoice_line.invoice_line_tax_ids or tax in invoice_line.invoice_line_tax_ids.mapped('children_tax_ids'):
+                            all_taxes = invoice_line.invoice_line_tax_ids.filtered(lambda x: x.amount_type != 'group') \
+                                        + invoice_line.invoice_line_tax_ids.mapped('children_tax_ids')
+                            following_taxes = all_taxes.filtered(lambda x: x.sequence > tax.sequence
+                                                                           or (x.sequence == tax.sequence and x.id > tax.id))
 
-                    tax_line_vals['tax_ids'] = [(6, 0, affected_taxes)]
+                    tax_line_vals['tax_ids'] = [(6, 0, following_taxes.ids)]
 
                 res.append(tax_line_vals)
         return res
-- 
GitLab