diff --git a/addons/product/models/product.py b/addons/product/models/product.py index 9ce704f9c7134957cfc891af8e0f9a3f17e5819b..9c335f1335b7ae3b71e1e8eec2ae72cf980904e9 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -428,10 +428,10 @@ class ProductProduct(models.Model): args.append((('categ_id', 'child_of', self._context['search_default_categ_id']))) return super(ProductProduct, self)._search(args, offset=offset, limit=limit, order=order, count=count, access_rights_uid=access_rights_uid) - @api.depends_context('display_default_code') + @api.depends_context('display_default_code', 'seller_id') def _compute_display_name(self): # `display_name` is calling `name_get()`` which is overidden on product - # to depend on `display_default_code` + # to depend on `display_default_code` and `seller_id` return super()._compute_display_name() def name_get(self): @@ -479,8 +479,8 @@ class ProductProduct(models.Model): variant = product.product_template_attribute_value_ids._get_combination_name() name = variant and "%s (%s)" % (product.name, variant) or product.name - sellers = [] - if partner_ids: + sellers = self.env['product.supplierinfo'].sudo().browse(self.env.context.get('seller_id')) or [] + if not sellers and partner_ids: product_supplier_info = supplier_info_by_template.get(product.product_tmpl_id, []) sellers = [x for x in product_supplier_info if x.product_id and x.product_id == product] if not sellers: diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index bf657c02949c52762d1a46867e2b7d63b384d2af..e1b54f1b49251bd986db14f0a1628b7da2633626 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1106,6 +1106,8 @@ class PurchaseOrderLine(models.Model): price_unit = seller.product_uom._compute_price(price_unit, self.product_uom) self.price_unit = price_unit + product_ctx = {'seller_id': seller.id, 'lang': get_lang(self.env, self.partner_id.lang).code} + self.name = self._get_product_purchase_description(self.product_id.with_context(product_ctx)) @api.depends('product_uom', 'product_qty', 'product_id.uom_id') def _compute_product_uom_qty(self): @@ -1211,7 +1213,7 @@ class PurchaseOrderLine(models.Model): lang=partner.lang, partner_id=partner.id, ) - name = product_lang.display_name + name = product_lang.with_context(seller_id=seller.id).display_name if product_lang.description_purchase: name += '\n' + product_lang.description_purchase diff --git a/addons/purchase_stock/tests/test_purchase_order.py b/addons/purchase_stock/tests/test_purchase_order.py index 4336403c0f19c256d30d5492cdd36a508278e6d7..391110a7597051a5ec579f5a3eaf8d5062857c4c 100644 --- a/addons/purchase_stock/tests/test_purchase_order.py +++ b/addons/purchase_stock/tests/test_purchase_order.py @@ -404,3 +404,45 @@ class TestPurchaseOrder(ValuationReconciliationTestCommon): _message_content = _purchase_order.message_ids.mapped("body")[0] self.assertIsNotNone(re.search(r"Received Quantity: 5.0 -> 10.0", _message_content), "Already received quantity isn't correctly taken into consideration") + + def test_pol_description(self): + """ + Suppose a product with several sellers, all with the same partner. On the purchase order, the product + description should be based on the correct seller + """ + self.env.user.write({'company_id': self.company_data['company'].id}) + + product = self.env['product.product'].create({ + 'name': 'Super Product', + 'seller_ids': [(0, 0, { + 'name': self.partner_a.id, + 'min_qty': 1, + 'price': 10, + 'product_code': 'C01', + 'product_name': 'Name01', + 'sequence': 1, + }), (0, 0, { + 'name': self.partner_a.id, + 'min_qty': 20, + 'price': 2, + 'product_code': 'C02', + 'product_name': 'Name02', + 'sequence': 2, + })] + }) + + orderpoint_form = Form(self.env['stock.warehouse.orderpoint']) + orderpoint_form.product_id = product + orderpoint_form.product_min_qty = 1 + orderpoint_form.product_max_qty = 0.000 + order_point = orderpoint_form.save() + + self.env['procurement.group'].run_scheduler() + + pol = self.env['purchase.order.line'].search([('product_id', '=', product.id)]) + self.assertEqual(pol.name, "[C01] Name01") + + with Form(pol.order_id) as po_form: + with po_form.order_line.edit(0) as pol_form: + pol_form.product_qty = 25 + self.assertEqual(pol.name, "[C02] Name02")