Skip to content
Snippets Groups Projects
Commit d5408b80 authored by mafo-odoo's avatar mafo-odoo
Browse files

[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#90594

Signed-off-by: default avatarArnold Moyaux <arm@odoo.com>
parent ee59c6f6
No related branches found
No related tags found
No related merge requests found
......@@ -728,9 +728,16 @@ 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:
self.name = self._get_product_purchase_description(self.product_id.with_context(**product_ctx))
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.depends('product_uom', 'product_qty', 'product_id.uom_id')
def _compute_product_uom_qty(self):
......
......@@ -115,3 +115,25 @@ class TestPurchase(SavepointCase):
vals['date_order'] = '2019-12-31 23:30:00'
purchase_order = PurchaseOrder.with_context(tz='Europe/Brussels').create(vals.copy())
self.assertTrue(purchase_order.name.startswith('PO/2020/'))
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
"""
company = self.env.user.company_id
vals = {
'partner_id': self.vendor.id,
'company_id': company.id,
}
po = Form(self.env['purchase.order'].create(vals))
self.product_consu.write({'seller_ids': [
(0, 0, {'name': self.vendor.id, 'product_code': 'ASUCODE'}),
]})
with po.order_line.new() as pol:
pol.product_id = self.product_consu
pol.product_qty = 1
pol.name = "New custom description"
pol.product_qty += 1
self.assertEqual(pol.name, "New custom description")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment