Skip to content

Commit

Permalink
[IMP] product_import: support company-specific vendors
Browse files Browse the repository at this point in the history
  • Loading branch information
florentx committed Jun 18, 2024
1 parent 1de9d2b commit 3998733
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
5 changes: 4 additions & 1 deletion product_import/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ def setUpClass(cls):
super().setUpClass()
cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True))
cls.wiz_model = cls.env["product.import"]
cls.supplier = cls.env["res.partner"].create({"name": "Catalogue Vendor"})
cls.company = cls.env["res.company"].create({"name": "Customer ABC"})
cls.supplier = cls.env["res.partner"].create(
{"name": "Catalogue Vendor", "company_id": cls.company.id}
)

def _mock(self, method_name):
return mock.patch.object(type(self.wiz_model), method_name)
Expand Down
23 changes: 15 additions & 8 deletions product_import/tests/test_product_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2022 Camptocamp SA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.exceptions import UserError
from .common import TestCommon

PARSED_CATALOG = {
Expand Down Expand Up @@ -48,6 +49,7 @@
},
],
"ref": "1387",
"company": {"name": "Customer ABC"},
"seller": {
"contact": False,
"email": False,
Expand All @@ -70,19 +72,24 @@ def setUpClass(cls):
cls.parsed_catalog["chatter_msg"] = []

def test_get_seller(self):
seller = self.wiz_model._get_seller(self.parsed_catalog)
# Not found
with self.assertRaises(UserError):
seller = self.wiz_model._get_seller(self.parsed_catalog)
# Found
seller = self.wiz_model.with_company(self.company.id)._get_seller(
self.parsed_catalog
)
self.assertEqual(seller, self.supplier)

def test_get_company_id(self):
# Test not found company_id
company_id = self.wiz_model._get_company_id(self.parsed_catalog)
self.assertIs(company_id, False)
# Test found company_id
new_catalog = dict(
self.parsed_catalog, company={"name": "My Company (San Francisco)"}
)
company_id = self.wiz_model._get_company_id(self.parsed_catalog)
self.assertEqual(company_id, self.company.id)
# Test not found company_id
new_catalog = dict(self.parsed_catalog)
del new_catalog["company"]
company_id = self.wiz_model._get_company_id(new_catalog)
self.assertEqual(company_id, self.env.ref("base.main_company").id)
self.assertIs(company_id, False)

def test_product_import(self):
# product.product
Expand Down
7 changes: 3 additions & 4 deletions product_import/wizard/product_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ def import_button(self):
if not catalogue.get("products"):
raise UserError(_("This catalogue doesn't have any product!"))
company_id = self._get_company_id(catalogue)
seller = self._get_seller(catalogue)
self.with_context(product_company_id=company_id)._create_products(
catalogue, seller, filename=self.product_filename
)
wiz = self.with_company(company_id).with_context(product_company_id=company_id)
seller = wiz._get_seller(catalogue)
wiz._create_products(catalogue, seller, filename=self.product_filename)
return {"type": "ir.actions.act_window_close"}

0 comments on commit 3998733

Please sign in to comment.