Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] product_import: support company-specific vendors #999

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
24 changes: 16 additions & 8 deletions product_import/tests/test_product_import.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 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 +50,7 @@
},
],
"ref": "1387",
"company": {"name": "Customer ABC"},
"seller": {
"contact": False,
"email": False,
Expand All @@ -70,19 +73,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"}
Loading