[IMP] product, purchase: vendor reference in multi-company

- Create 2 companies A & B
- On a product P, define 2 suppliers (same vendor), one for each
  company, but with a different Vendor Product Code
- Create a PO in A for P

Both supplier codes are proposed in the Many2one widget, while only the
code for A is expected.

Fixes #27857
opw-1894952

closes odoo/odoo#28402
This commit is contained in:
Nicolas Martinelli
2018-11-06 08:34:26 +00:00
parent 22ee6ebbfc
commit 478691b95d
3 changed files with 44 additions and 0 deletions
+6
View File
@@ -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 (
+37
View File
@@ -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")
+1
View File
@@ -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: