From 16dd9ae446588b32471bb8e5c7765320d5f78dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Wed, 28 Jan 2026 15:58:01 +0100 Subject: [PATCH] Set product on invoice line base on allowance/charge reason code from UBL invoice --- modules/edocument_ubl/edocument.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/modules/edocument_ubl/edocument.py b/modules/edocument_ubl/edocument.py index 637dd125ba..8151564713 100644 --- a/modules/edocument_ubl/edocument.py +++ b/modules/edocument_ubl/edocument.py @@ -500,6 +500,7 @@ class Invoice(Model): 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 @@ class Invoice(Model): 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 @@ class Invoice(Model): 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 @@ class Invoice(Model): 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)