changeset 33d9a972aec9 in modules/account_invoice:default
details: 
https://hg.tryton.org/modules/account_invoice?cmd=changeset&node=33d9a972aec9
description:
        Ensure unique taxes when applying tax rule

        Since issue10841 the taxes must be unique so the tax rule application 
must
        result on unique taxes.

        issue11230
        review419361003
diffstat:

 invoice.py |  24 ++++++++++++------------
 1 files changed, 12 insertions(+), 12 deletions(-)

diffs (77 lines):

diff -r 401244e9cb0c -r 33d9a972aec9 invoice.py
--- a/invoice.py        Sat Jun 04 00:24:52 2022 +0200
+++ b/invoice.py        Sun Jul 17 00:00:56 2022 +0200
@@ -2271,19 +2271,19 @@
         if type_ == 'in':
             with Transaction().set_context(date=date):
                 self.account = self.product.account_expense_used
-            taxes = []
+            taxes = set()
             pattern = self._get_tax_rule_pattern()
             for tax in self.product.supplier_taxes_used:
                 if party and party.supplier_tax_rule:
                     tax_ids = party.supplier_tax_rule.apply(tax, pattern)
                     if tax_ids:
-                        taxes.extend(tax_ids)
+                        taxes.update(tax_ids)
                     continue
-                taxes.append(tax)
+                taxes.add(tax.id)
             if party and party.supplier_tax_rule:
                 tax_ids = party.supplier_tax_rule.apply(None, pattern)
                 if tax_ids:
-                    taxes.extend(tax_ids)
+                    taxes.update(tax_ids)
             self.taxes = taxes
 
             if self.company and self.company.purchase_taxes_expense:
@@ -2294,19 +2294,19 @@
         else:
             with Transaction().set_context(date=date):
                 self.account = self.product.account_revenue_used
-            taxes = []
+            taxes = set()
             pattern = self._get_tax_rule_pattern()
             for tax in self.product.customer_taxes_used:
                 if party and party.customer_tax_rule:
                     tax_ids = party.customer_tax_rule.apply(tax, pattern)
                     if tax_ids:
-                        taxes.extend(tax_ids)
+                        taxes.update(tax_ids)
                     continue
-                taxes.append(tax.id)
+                taxes.add(tax.id)
             if party and party.customer_tax_rule:
                 tax_ids = party.customer_tax_rule.apply(None, pattern)
                 if tax_ids:
-                    taxes.extend(tax_ids)
+                    taxes.update(tax_ids)
             self.taxes = taxes
 
         category = self.product.default_uom.category
@@ -2325,7 +2325,7 @@
     def on_change_account(self):
         if self.product:
             return
-        taxes = []
+        taxes = set()
         party = None
         if self.invoice and self.invoice.party:
             party = self.invoice.party
@@ -2350,13 +2350,13 @@
                 if tax_rule:
                     tax_ids = tax_rule.apply(tax, pattern)
                     if tax_ids:
-                        taxes.extend(tax_ids)
+                        taxes.update(tax_ids)
                     continue
-                taxes.append(tax)
+                taxes.add(tax.id)
             if tax_rule:
                 tax_ids = tax_rule.apply(None, pattern)
                 if tax_ids:
-                    taxes.extend(tax_ids)
+                    taxes.update(tax_ids)
         self.taxes = taxes
 
     @classmethod

Reply via email to