details:   https://code.tryton.org/tryton/commit/4c43e0c46eb9
branch:    default
user:      Cédric Krier <[email protected]>
date:      Mon Apr 13 17:30:06 2026 +0200
description:
        Render prepaid amount in UBL invoice

        Closes #14766
diffstat:

 modules/edocument_ubl/CHANGELOG                 |   1 +
 modules/edocument_ubl/edocument.py              |  11 +++++++++++
 modules/edocument_ubl/template/2/CreditNote.xml |   3 ++-
 modules/edocument_ubl/template/2/Invoice.xml    |   3 ++-
 4 files changed, 16 insertions(+), 2 deletions(-)

diffs (55 lines):

diff -r 7d2e1761cee2 -r 4c43e0c46eb9 modules/edocument_ubl/CHANGELOG
--- a/modules/edocument_ubl/CHANGELOG   Sat Apr 11 08:42:50 2026 +0200
+++ b/modules/edocument_ubl/CHANGELOG   Mon Apr 13 17:30:06 2026 +0200
@@ -1,3 +1,4 @@
+* Render prepaid amount
 * Fill invoice source amounts instead of checking amounts
 * Filter the MIME type of the additional documents allowed by the specification
 * Use VATEX as tax exemption reason code
diff -r 7d2e1761cee2 -r 4c43e0c46eb9 modules/edocument_ubl/edocument.py
--- a/modules/edocument_ubl/edocument.py        Sat Apr 11 08:42:50 2026 +0200
+++ b/modules/edocument_ubl/edocument.py        Mon Apr 13 17:30:06 2026 +0200
@@ -271,6 +271,17 @@
                         return
                 return product.unece_allowance_charge_code
 
+    @cached_property
+    def prepaid_amount(self):
+        def balance(line):
+            if self.invoice.currency == line.second_currency:
+                return line.amount_second_currency
+            elif self.invoice.currency == self.invoice.company.currency:
+                return line.debit - line.credit
+            else:
+                return 0
+        return sum(map(balance, self.invoice.lines_to_pay))
+
     @classmethod
     def parse(cls, document):
         pool = Pool()
diff -r 7d2e1761cee2 -r 4c43e0c46eb9 
modules/edocument_ubl/template/2/CreditNote.xml
--- a/modules/edocument_ubl/template/2/CreditNote.xml   Sat Apr 11 08:42:50 
2026 +0200
+++ b/modules/edocument_ubl/template/2/CreditNote.xml   Mon Apr 13 17:30:06 
2026 +0200
@@ -124,7 +124,8 @@
     <py:if test="this.invoice.total_amount != (this.invoice.untaxed_amount + 
this.invoice.tax_amount)">
         <cbc:PayableRoundingAmount py:attrs="{'currencyID': 
this.invoice.currency.code}">${-(this.invoice.total_amount - 
this.invoice.untaxed_amount - 
this.invoice.tax_amount)}</cbc:PayableRoundingAmount>
     </py:if>
-    <cbc:PayableAmount py:attrs="{'currencyID': 
this.invoice.currency.code}">${-this.invoice.total_amount}</cbc:PayableAmount>
+    <cbc:PrepaidAmount py:if="this.prepaid_amount" py:attrs="{'currencyID': 
this.invoice.currency.code}">${-this.prepaid_amount}</cbc:PrepaidAmount>
+    <cbc:PayableAmount py:attrs="{'currencyID': 
this.invoice.currency.code}">${-this.invoice.total_amount + 
this.prepaid_amount}</cbc:PayableAmount>
 </cac:LegalMonetaryTotal>
 <cac:CreditNoteLine py:for="line_id, line in enumerate(this.lines, 1)">
     <cbc:ID>${line_id}</cbc:ID>
diff -r 7d2e1761cee2 -r 4c43e0c46eb9 
modules/edocument_ubl/template/2/Invoice.xml
--- a/modules/edocument_ubl/template/2/Invoice.xml      Sat Apr 11 08:42:50 
2026 +0200
+++ b/modules/edocument_ubl/template/2/Invoice.xml      Mon Apr 13 17:30:06 
2026 +0200
@@ -124,7 +124,8 @@
     <py:if test="this.invoice.total_amount != (this.invoice.untaxed_amount + 
this.invoice.tax_amount)">
         <cbc:PayableRoundingAmount py:attrs="{'currencyID': 
this.invoice.currency.code}">${this.invoice.total_amount - 
this.invoice.untaxed_amount - 
this.invoice.tax_amount}</cbc:PayableRoundingAmount>
     </py:if>
-    <cbc:PayableAmount py:attrs="{'currencyID': 
this.invoice.currency.code}">${this.invoice.total_amount}</cbc:PayableAmount>
+    <cbc:PrepaidAmount py:if="this.prepaid_amount" py:attrs="{'currencyID': 
this.invoice.currency.code}">${this.prepaid_amount}</cbc:PrepaidAmount>
+    <cbc:PayableAmount py:attrs="{'currencyID': 
this.invoice.currency.code}">${this.invoice.total_amount - 
this.prepaid_amount}</cbc:PayableAmount>
 </cac:LegalMonetaryTotal>
 <cac:InvoiceLine py:for="line_id, line in enumerate(this.lines, 1)">
     <cbc:ID>${line_id}</cbc:ID>

Reply via email to