From 131c06703b2bfe930f0d76b5b69c8ecba23fe8e2 Mon Sep 17 00:00:00 2001 From: Nicolas Galler Date: Tue, 29 Dec 2020 16:06:02 +0000 Subject: [PATCH] [FIX] purchase_stock: do not include internal notes in generated PO Behavior prior to this commit: When a PO is generated (via reordering rule, mto rule, or manual replenish), the description on the PO line includes the internal notes. Behavior after this commit: The description on the PO line does not include the internal notes. Note: Per c324526ad061, the description on the picking also does not include the internal notes (anymore), and the test has been updated to reflect that. opw-24222438 closes odoo/odoo#64883 X-original-commit: 5db67fb2931517ae94fe0396ef80e9ad997e59cd Signed-off-by: Nicolas Galler --- addons/purchase_stock/models/purchase.py | 10 +++++----- addons/purchase_stock/tests/common.py | 1 + addons/purchase_stock/tests/test_purchase_lead_time.py | 8 ++++---- addons/purchase_stock/tests/test_reordering_rule.py | 2 ++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index b8a6a7eb00b..4926ca15f2d 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -460,15 +460,15 @@ class PurchaseOrderLine(models.Model): @api.model def _prepare_purchase_order_line_from_procurement(self, product_id, product_qty, product_uom, company_id, values, po): - line_description = product_id._get_description(po.picking_type_id) + line_description = '' if values.get('product_description_variants'): - line_description += values['product_description_variants'] + line_description = values['product_description_variants'] supplier = values.get('supplier') res = self._prepare_purchase_order_line(product_id, product_qty, product_uom, company_id, supplier, po) # We need to keep the vendor name set in _prepare_purchase_order_line. To avoid redundancy # in the line name, we add the line_description only if different from the product name. # This way, we shoud not lose any valuable information. - if product_id.name != line_description: + if line_description and product_id.name != line_description: res['name'] += '\n' + line_description res['move_dest_ids'] = [(4, x.id) for x in values.get('move_dest_ids', [])] res['orderpoint_id'] = values.get('orderpoint_id', False) and values.get('orderpoint_id').id @@ -490,9 +490,9 @@ class PurchaseOrderLine(models.Model): args can be merged. If it returns an empty record then a new line will be created. """ - description_picking = product_id._get_description(self.order_id.picking_type_id) or '' + description_picking = '' if values.get('product_description_variants'): - description_picking += values['product_description_variants'] + description_picking = values['product_description_variants'] lines = self.filtered( lambda l: l.propagate_cancel == values['propagate_cancel'] and ((values['orderpoint_id'] and not values['move_dest_ids']) and l.orderpoint_id == values['orderpoint_id'] or True) diff --git a/addons/purchase_stock/tests/common.py b/addons/purchase_stock/tests/common.py index f3a98e049ea..d0443240d76 100644 --- a/addons/purchase_stock/tests/common.py +++ b/addons/purchase_stock/tests/common.py @@ -38,6 +38,7 @@ class PurchaseTestCommon(TestStockCommon): cls.t_shirt = cls.env['product.product'].create({ 'name': 'T-shirt', + 'description': 'Internal Notes', 'route_ids': [(6, 0, [cls.route_buy, cls.route_mto])], 'seller_ids': [(0, 0, {'name': cls.partner_1.id, 'delay': 5})] }) diff --git a/addons/purchase_stock/tests/test_purchase_lead_time.py b/addons/purchase_stock/tests/test_purchase_lead_time.py index 4bb08d099d5..d99c084dbd7 100644 --- a/addons/purchase_stock/tests/test_purchase_lead_time.py +++ b/addons/purchase_stock/tests/test_purchase_lead_time.py @@ -242,9 +242,9 @@ class TestPurchaseLeadTime(PurchaseTestCommon): self.t_shirt.name, '/', self.env.company, order_1_values) ]) purchase_order = self.env['purchase.order.line'].search([('product_id', '=', self.t_shirt.id)], limit=1).order_id - order_line_description = purchase_order.order_line.product_id._get_description(purchase_order.picking_type_id) + order_line_description = purchase_order.order_line.product_id.description_pickingin or '' self.assertEqual(len(purchase_order.order_line), 1, 'wrong number of order line is created') - self.assertEqual(purchase_order.order_line.name, t_shirt.display_name + "\n" + order_line_description + "Color (Red)", 'wrong description in po lines') + self.assertEqual(purchase_order.order_line.name, t_shirt.display_name + "\n" + "Color (Red)", 'wrong description in po lines') procurement_values['product_description_variants'] = 'Color (Red)' order_2_values = procurement_values @@ -264,8 +264,8 @@ class TestPurchaseLeadTime(PurchaseTestCommon): self.t_shirt.name, '/', self.env.company, order_3_values) ]) self.assertEqual(len(purchase_order.order_line), 2, 'line with different custom value should not be merged') - self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 15).name, t_shirt.display_name + "\n" + order_line_description + "Color (Red)", 'wrong description in po lines') - self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 10).name, t_shirt.display_name + "\n" + order_line_description + "Color (Green)", 'wrong description in po lines') + self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 15).name, t_shirt.display_name + "\n" + "Color (Red)", 'wrong description in po lines') + self.assertEqual(purchase_order.order_line.filtered(lambda x: x.product_qty == 10).name, t_shirt.display_name + "\n" + "Color (Green)", 'wrong description in po lines') purchase_order.button_confirm() self.assertEqual(purchase_order.picking_ids[0].move_ids_without_package.filtered(lambda x: x.product_uom_qty == 15).description_picking, t_shirt.display_name + "\n" + order_line_description + "Color (Red)", 'wrong description in picking') diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index 6fd46c2f0dc..b5f7d40bb4b 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -21,6 +21,7 @@ class TestReorderingRule(TransactionCase): product_form = Form(cls.env['product.product']) product_form.name = 'Product A' product_form.type = 'product' + product_form.description = 'Internal Notes' with product_form.seller_ids.new() as seller: seller.name = cls.partner product_form.route_ids.add(cls.env.ref('purchase_stock.route_warehouse0_buy')) @@ -66,6 +67,7 @@ class TestReorderingRule(TransactionCase): # On the po generated, the source document should be the name of the reordering rule self.assertEqual(order_point.name, purchase_order.origin, 'Source document on purchase order should be the name of the reordering rule.') self.assertEqual(purchase_order.order_line.product_qty, 10) + self.assertEqual(purchase_order.order_line.name, 'Product A') # Increase the quantity on the RFQ before confirming it purchase_order.order_line.product_qty = 12