details:   https://code.tryton.org/tryton/commit/550efceff67d
branch:    default
user:      Cédric Krier <[email protected]>
date:      Wed Jan 28 15:58:01 2026 +0100
description:
        Set product on invoice line base on allowance/charge reason code from 
UBL invoice
diffstat:

 modules/edocument_ubl/edocument.py |  28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)

diffs (59 lines):

diff -r 69beb4452faa -r 550efceff67d modules/edocument_ubl/edocument.py
--- a/modules/edocument_ubl/edocument.py        Mon Jan 26 15:38:06 2026 +0100
+++ b/modules/edocument_ubl/edocument.py        Wed Jan 28 15:58:01 2026 +0100
@@ -500,6 +500,7 @@
         AccountConfiguration = pool.get('account.configuration')
         Line = pool.get('account.invoice.line')
         Tax = pool.get('account.tax')
+        Product = pool.get('product.product')
 
         account_configuration = AccountConfiguration(1)
 
@@ -508,6 +509,19 @@
 
         indicator = allowance_charge.findtext('./{*}ChargeIndicator')
         line.quantity = {'true': 1, 'false': -1}[indicator]
+
+        line.product = None
+        if code := allowance_charge.findtext('./{*}AllowanceChargeReasonCode'):
+            try:
+                line.product, = Product.search(['OR',
+                        ('unece_allowance_charge_code', '=', code),
+                        ('unece_special_service_code', '=', code),
+                        ], limit=1)
+            except ValueError:
+                pass
+        if line.product:
+            line.on_change_product()
+
         line.account = account_configuration.get_multivalue(
             'default_category_account_expense',
             company=company.id)
@@ -736,6 +750,7 @@
         AccountConfiguration = pool.get('account.configuration')
         Line = pool.get('account.invoice.line')
         Tax = pool.get('account.tax')
+        Product = pool.get('product.product')
 
         account_configuration = AccountConfiguration(1)
 
@@ -744,6 +759,19 @@
 
         indicator = allowance_charge.findtext('./{*}ChargeIndicator')
         line.quantity = {'true': -1, 'false': 1}[indicator]
+
+        line.product = None
+        if code := allowance_charge.findtext('./{*}AllowanceChargeReasonCode'):
+            try:
+                line.product, = Product.search(['OR',
+                        ('unece_allowance_charge_code', '=', code),
+                        ('unece_special_service_code', '=', code),
+                        ], limit=1)
+            except ValueError:
+                pass
+        if line.product:
+            line.on_change_product()
+
         line.account = account_configuration.get_multivalue(
             'default_category_account_expense',
             company=company.id)

Reply via email to