From 735d18bfab73cb0caecbe7df4c4a35beeb94a41c Mon Sep 17 00:00:00 2001 From: Florent Xicluna Date: Fri, 1 Dec 2023 10:51:37 +0100 Subject: [PATCH] [IMP] product_import: find product by internal reference --- product_import/wizard/product_import.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/product_import/wizard/product_import.py b/product_import/wizard/product_import.py index f86cafe7a49..d29a344ceb2 100644 --- a/product_import/wizard/product_import.py +++ b/product_import/wizard/product_import.py @@ -148,16 +148,21 @@ def _prepare_supplierinfo(self, seller_info, product): result.append((0, 0, seller_info)) return result - def _existing_product(self, barcode, company_id): - product_domain = [("barcode", "=", barcode)] + def _search_product(self, domain, company_id): if company_id: - product_domain += [("company_id", "=", company_id)] + domain = domain + [("company_id", "=", company_id)] return ( self.env["product.product"] .with_context(active_test=False) - .search(product_domain, limit=1) + .search(domain, order="active DESC", limit=1) ) + def _existing_product(self, barcode, code, company_id): + product = None + if barcode: + product = self._search_product([("barcode", "=", barcode)], company_id) + return product or self._search_product([("default_code", "=", code)], company_id) + @api.model def _prepare_product(self, parsed_product, chatter_msg, seller=None): # By default records product.product are created with company_id=False. @@ -165,11 +170,6 @@ def _prepare_product(self, parsed_product, chatter_msg, seller=None): # Setting "product_import_set_company" change the behavior. # Beware that barcode is unique key of product.template model # Can be changed by OCA add-on "product_barcode_constraint_per_company" - if not parsed_product["barcode"]: - chatter_msg.append( - _("Cannot import product without barcode: %s") % (parsed_product,) - ) - return False import_company = self.env["res.company"].browse( self.env.context.get("product_company_id") ) @@ -178,6 +178,7 @@ def _prepare_product(self, parsed_product, chatter_msg, seller=None): ) product = self._existing_product( parsed_product["barcode"], + parsed_product["code"], company_id=product_company_id, ) uom = self._bdimport._match_uom(parsed_product["uom"], chatter_msg)