Skip to content

Commit

Permalink
[IMP] product_import: find product by internal reference
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Dec 1, 2023
1 parent 222620a commit 735d18b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions product_import/wizard/product_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,28 +148,28 @@ 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)]

Check warning on line 153 in product_import/wizard/product_import.py

View check run for this annotation

Codecov / codecov/patch

product_import/wizard/product_import.py#L153

Added line #L153 was not covered by tests
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.
# Only the pricelist (product.supplierinfo) is company-specific.
# 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")
)
Expand All @@ -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)
Expand Down

0 comments on commit 735d18b

Please sign in to comment.