From 3fa052d5419b5170d4d7577719ef4d488f4ae0f2 Mon Sep 17 00:00:00 2001 From: Davan CHIEM DAO Date: Fri, 18 Mar 2022 11:12:21 +0000 Subject: [PATCH] [FIX] l10n_it_edi: Product matching from invoice import This fixes erroneous matching of product when the product code in an invoice is ambiguous and fixes a missuse of the label from a product rather than the one on the invoice Previously, a product would be set on an invoice line even if several products share the product code and when a product is set the label is the one of the matched product Now, a product is set if the code matches one and only one product and the label used is always the one from the invoice closes odoo/odoo#87313 Task: 2764978 X-original-commit: 47d5dff9f9a8eb0b4eebdf56e2a2d46618972453 Signed-off-by: Josse Colpaert Signed-off-by: Florian Gilbert --- addons/l10n_it_edi/models/account_edi_format.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/addons/l10n_it_edi/models/account_edi_format.py b/addons/l10n_it_edi/models/account_edi_format.py index 7202d37cd08..c731deb3ee6 100644 --- a/addons/l10n_it_edi/models/account_edi_format.py +++ b/addons/l10n_it_edi/models/account_edi_format.py @@ -431,10 +431,6 @@ class AccountEdiFormat(models.Model): invoice_line_form.sequence = int(line_elements[0].text) # Product. - line_elements = element.xpath('.//Descrizione') - if line_elements: - invoice_line_form.name = " ".join(line_elements[0].text.split()) - elements_code = element.xpath('.//CodiceArticolo') if elements_code: for element_code in elements_code: @@ -446,18 +442,23 @@ class AccountEdiFormat(models.Model): invoice_line_form.product_id = product break if partner: - product_supplier = self.env['product.supplierinfo'].search([('partner_id', '=', partner.id), ('product_code', '=', code.text)], limit=1) - if product_supplier and product_supplier.product_id: + product_supplier = self.env['product.supplierinfo'].search([('partner_id', '=', partner.id), ('product_code', '=', code.text)], limit=2) + if product_supplier and len(product_supplier) == 1 and product_supplier.product_id: invoice_line_form.product_id = product_supplier.product_id break if not invoice_line_form.product_id: for element_code in elements_code: code = element_code.xpath('.//CodiceValore')[0] - product = self.env['product.product'].search([('default_code', '=', code.text)], limit=1) - if product: + product = self.env['product.product'].search([('default_code', '=', code.text)], limit=2) + if product and len(product) == 1: invoice_line_form.product_id = product break + # Label. + line_elements = element.xpath('.//Descrizione') + if line_elements: + invoice_line_form.name = " ".join(line_elements[0].text.split()) + # Price Unit. line_elements = element.xpath('.//PrezzoUnitario') if line_elements: