details:   https://code.tryton.org/tryton/commit/dbba242942a5
branch:    default
user:      Cédric Krier <[email protected]>
date:      Fri Jan 23 13:02:19 2026 +0100
description:
        Group tax lines per tax having the same UNECE codes in UBL invoice
diffstat:

 modules/edocument_ubl/edocument.py |  26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diffs (47 lines):

diff -r 1974969ddafc -r dbba242942a5 modules/edocument_ubl/edocument.py
--- a/modules/edocument_ubl/edocument.py        Fri Jan 23 11:05:13 2026 +0100
+++ b/modules/edocument_ubl/edocument.py        Fri Jan 23 13:02:19 2026 +0100
@@ -6,6 +6,7 @@
 import mimetypes
 import os
 from base64 import b64decode, b64encode
+from collections import namedtuple
 from decimal import Decimal
 from io import BytesIO
 from itertools import chain, groupby
@@ -184,13 +185,32 @@
 
     @property
     def taxes(self):
+        class Tax(namedtuple(
+                    'Tax',
+                    ('type', 'rate', 'unece_category_code', 'unece_code'))):
+            @classmethod
+            def from_line(cls, line):
+                return Tax(
+                    type=line.tax.type,
+                    rate=line.tax.rate,
+                    unece_category_code=line.tax.unece_category_code,
+                    unece_code=line.tax.unece_code)
+        TaxLine = namedtuple('TaxLine', ('base', 'amount', 'tax'))
         for group, lines in groupby(sorted(
                     self.invoice.taxes,
                     key=sortable_values(self._taxes_key)),
                 key=self._taxes_key):
-            lines = list(lines)
-            amount = sum(l.amount for l in lines)
-            yield group, lines, amount
+            tax_lines, tax_amount = [], 0
+            for tax, lines in groupby(sorted(
+                        lines, key=sortable_values(Tax.from_line)),
+                    key=Tax.from_line):
+                amount = base = 0
+                for line in lines:
+                    tax_amount += line.amount
+                    base += line.base
+                    amount += line.amount
+                tax_lines.append(TaxLine(base=base, amount=amount, tax=tax))
+            yield group, tax_lines, amount
 
     def _taxes_key(self, line):
         return ()

Reply via email to