Skip to content

Commit

Permalink
[IMP] search for product related to channel's company
Browse files Browse the repository at this point in the history
  • Loading branch information
clementmbr committed May 16, 2024
1 parent 224dcdb commit 4ab2f79
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions sale_import_base/models/sale_channel_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,34 @@ def _prepare_sale_line_vals(self, data, sale_order):
return [self._prepare_sale_line(line, sale_order) for line in data["lines"]]

def _prepare_sale_line(self, line_data, sale_order):
channel = self.chunk_id.reference
company_id = channel.company_id

product = self.env["product.product"].search(
[("default_code", "=", line_data["product_code"])]
[
("default_code", "=", line_data["product_code"]),
("product_tmpl_id.company_id", "=", company_id.id),
]
)
if not product:
raise ValidationError(
_("Missing product {}").format(line_data["product_code"])
_(
"There is no active product with the Internal Reference %(code)s "
"and related to the company %(company)s."
)
% {"code": line_data["product_code"], "company": company_id.name}
)
elif len(product) > 1:
raise ValidationError(
_("%(product_num)s products found for the code %(code)s")
% {"product_num": len(product), "code": line_data["product_code"]}
_(
"%(product_num)s products found for the code %(code)s and related "
"to the company %(company)s."
)
% {
"product_num": len(product),
"code": line_data["product_code"],
"company": company_id.name,
}
)
vals = {
"product_id": product.id,
Expand Down

0 comments on commit 4ab2f79

Please sign in to comment.