diff --git a/modules/edocument_ubl/CHANGELOG b/modules/edocument_ubl/CHANGELOG
index 315289c72f..b1d4a0f6a1 100644
--- a/modules/edocument_ubl/CHANGELOG
+++ b/modules/edocument_ubl/CHANGELOG
@@ -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 --git a/modules/edocument_ubl/edocument.py b/modules/edocument_ubl/edocument.py
index ae20bbc20e..6944e8f648 100644
--- a/modules/edocument_ubl/edocument.py
+++ b/modules/edocument_ubl/edocument.py
@@ -271,6 +271,17 @@ class Invoice(Model):
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 --git a/modules/edocument_ubl/template/2/CreditNote.xml b/modules/edocument_ubl/template/2/CreditNote.xml
index bdf1a9a423..2179db01a9 100644
--- a/modules/edocument_ubl/template/2/CreditNote.xml
+++ b/modules/edocument_ubl/template/2/CreditNote.xml
@@ -124,7 +124,8 @@ this repository contains the full copyright notices and license terms. -->
${-(this.invoice.total_amount - this.invoice.untaxed_amount - this.invoice.tax_amount)}
- ${-this.invoice.total_amount}
+ ${-this.prepaid_amount}
+ ${-this.invoice.total_amount + this.prepaid_amount}
${line_id}
diff --git a/modules/edocument_ubl/template/2/Invoice.xml b/modules/edocument_ubl/template/2/Invoice.xml
index be9cc7ddba..56de7a1431 100644
--- a/modules/edocument_ubl/template/2/Invoice.xml
+++ b/modules/edocument_ubl/template/2/Invoice.xml
@@ -124,7 +124,8 @@ this repository contains the full copyright notices and license terms. -->
${this.invoice.total_amount - this.invoice.untaxed_amount - this.invoice.tax_amount}
- ${this.invoice.total_amount}
+ ${this.prepaid_amount}
+ ${this.invoice.total_amount - this.prepaid_amount}
${line_id}