From f48d9a68bc9bcb254d2a89f661bb95ae51af7e62 Mon Sep 17 00:00:00 2001 From: mafo-odoo Date: Thu, 28 Apr 2022 13:53:13 +0000 Subject: [PATCH] [FIX] purchase: no reset custom description in PO if qt change Step to reproduce: Install purchase Create a purchase order Set a vendo and a product that has this vendor in its vendor list Set a product name in the line of the vendor in the product purchase section (you will need to add the field) Change the description of the product Change the quantity of the product Expected behavior: The description stay the custom input you just set Current behavior: The description is reset to its default value Explanation: When changing the quantity the vendor from the product vendors can change. Then its vendor product name and code can change and thus the default description in the purchase order. To solve that we need to differentiate a custom description from a default one and only update the descritpion when the quantity changes if the descritpion is a default one (and not a sutom one) opw-2827667 closes odoo/odoo#90923 X-original-commit: 96bbe252ecbb94600632a1a5cb449b8d2810d2c0 Signed-off-by: Arnold Moyaux Signed-off-by: Fockedey Martin (mafo) --- addons/purchase/models/purchase.py | 11 +++++++++-- addons/purchase/tests/test_purchase.py | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) 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")