diff --git a/addons/product/models/product.py b/addons/product/models/product.py index b755fd5c2a4..0806370c998 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -381,6 +381,7 @@ class ProductProduct(models.Model): partner_ids = [partner_id, self.env['res.partner'].browse(partner_id).commercial_partner_id.id] else: partner_ids = [] + company_id = self.env.context.get('company_id') # all user don't have access to seller and partner # check access and use superuser @@ -399,6 +400,11 @@ class ProductProduct(models.Model): sellers = [x for x in product.seller_ids if (x.name.id in partner_ids) and (x.product_id == product)] if not sellers: sellers = [x for x in product.seller_ids if (x.name.id in partner_ids) and not x.product_id] + # Filter out sellers based on the company. This is done afterwards for a better + # code readability. At this point, only a few sellers should remain, so it should + # not be a performance issue. + if company_id: + sellers = [x for x in sellers if x.company_id.id in [company_id, False]] if sellers: for s in sellers: seller_variant = s.product_name and ( diff --git a/addons/product/tests/test_seller.py b/addons/product/tests/test_seller.py index 36693317c34..830b277da1d 100644 --- a/addons/product/tests/test_seller.py +++ b/addons/product/tests/test_seller.py @@ -10,6 +10,11 @@ class TestSeller(TransactionCase): super(TestSeller, self).setUp() self.product_service = self.env.ref('product.product_product_2') self.product_service.default_code = 'DEFCODE' + self.product_consu = self.env['product.product'].create({ + 'name': 'Boudin', + 'type': 'consu', + }) + self.product_consu.default_code = 'DEFCODE' self.asustec = self.env.ref('base.res_partner_1') self.camptocamp = self.env.ref('base.res_partner_12') @@ -26,3 +31,35 @@ class TestSeller(TransactionCase): .with_context(partner_id=self.camptocamp.id)\ .code self.assertEqual('C2CCODE', context_code, "Partner's code not used in product name with context set") + + def test_20_sellers_company(self): + company_a = self.env.user.company_id + company_b = self.env['res.company'].create({ + 'name': 'Saucisson Inc.', + }) + self.product_consu.write({'seller_ids': [ + (0, 0, {'name': self.asustec.id, 'product_code': 'A', 'company_id': company_a.id}), + (0, 0, {'name': self.asustec.id, 'product_code': 'B', 'company_id': company_b.id}), + (0, 0, {'name': self.asustec.id, 'product_code': 'NO', 'company_id': False}), + ]}) + + names = self.product_consu.with_context( + partner_id=self.asustec.id, + ).name_get() + ref = set([x[1] for x in names]) + self.assertEqual(len(names), 3, "3 vendor references should have been found") + self.assertEqual(ref, {'[A] Boudin', '[B] Boudin', '[NO] Boudin'}, "Incorrect vendor reference list") + names = self.product_consu.with_context( + partner_id=self.asustec.id, + company_id=company_a.id, + ).name_get() + ref = set([x[1] for x in names]) + self.assertEqual(len(names), 2, "2 vendor references should have been found") + self.assertEqual(ref, {'[A] Boudin', '[NO] Boudin'}, "Incorrect vendor reference list") + names = self.product_consu.with_context( + partner_id=self.asustec.id, + company_id=company_b.id, + ).name_get() + ref = set([x[1] for x in names]) + self.assertEqual(len(names), 2, "2 vendor references should have been found") + self.assertEqual(ref, {'[B] Boudin', '[NO] Boudin'}, "Incorrect vendor reference list") diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index c500f5c6cb4..2bbf930f3c8 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -576,6 +576,7 @@ class PurchaseOrderLine(models.Model): product_lang = self.product_id.with_context( lang=self.partner_id.lang, partner_id=self.partner_id.id, + company_id=self.company_id.id, ) self.name = product_lang.display_name if product_lang.description_purchase: