[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 <jco@odoo.com>
Signed-off-by: Florian Gilbert <flg@odoo.com>
This commit is contained in:
Davan CHIEM DAO
2022-03-28 07:35:05 +02:00
committed by dbkosky
parent 7dea86387d
commit 3fa052d541
@@ -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: