diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index de017ae648a..ed511de6d56 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -1231,8 +1231,15 @@ 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} - if seller.product_name: + + default_names = [] + vendors = self.product_id._prepare_sellers({}) + for vendor in vendors: + product_ctx = {'seller_id': vendor.id, 'lang': get_lang(self.env, self.partner_id.lang).code} + default_names.append(self._get_product_purchase_description(self.product_id.with_context(product_ctx))) + + if (self.name in default_names or not self.name): + 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.onchange('product_id', 'product_qty', 'product_uom') diff --git a/addons/purchase/tests/test_purchase.py b/addons/purchase/tests/test_purchase.py index 983ad102107..1c0267682d2 100644 --- a/addons/purchase/tests/test_purchase.py +++ b/addons/purchase/tests/test_purchase.py @@ -248,3 +248,21 @@ class TestPurchase(AccountTestInvoicingCommon): self.assertEqual(po.order_line[0].price_unit, 200) self.assertEqual(po.order_line[1].price_unit, 1200) + + def test_on_change_quantity_description(self): + """ + When a user changes the quantity of a product in a purchase order it + should not change the description if the descritpion was changed by + the user before + """ + self.env.user.write({'company_id': self.company_data['company'].id}) + + po = Form(self.env['purchase.order']) + po.partner_id = self.partner_a + with po.order_line.new() as pol: + pol.product_id = self.product_a + pol.product_qty = 1 + + pol.name = "New custom description" + pol.product_qty += 1 + self.assertEqual(pol.name, "New custom description")