From 4cc2b3bcca613dfb37bb77e5fef6de6e044e3399 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Mon, 3 Oct 2022 13:30:37 +0000 Subject: [PATCH] [FIX] sale_stock, purchase_stock: use product name as `stock.move` name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a Kit product "Kit 1": - Add a BOM with a component “C1” - Add a sales description - Create another kit product without a sales description "Kit 2": - Add a BOM with a component "C2" - Make sure you have a qty of “C1” and "C2" - Create a SO: - Add "Kit 1" and "Kit 2" - Add any other storable product - Confirm the SO - Go to the delivery → validate it - Print the delivery slip Problem: The report doesn’t contain the kit product. Because in the report, the `stock.move.line` are filtered by checking the name of their move if it has the same name as the product in the bill of material, but like the `stock.move` has the name ('description') of the `sale.order.line` instead of the product name, the lines are filtered and not displayed: https://github.com/odoo/odoo/blob/14.0/addons/mrp/report/report_deliveryslip.xml#L9 The behavior is the same for purchase orders opw-2960467 closes odoo/odoo#105158 X-original-commit: be25cea0d882bb03a4873821fdb788a0890ba49a Signed-off-by: Tiffany Chang Signed-off-by: Djamel Touati (otd) --- addons/purchase_stock/models/purchase.py | 2 +- .../sale_mrp/tests/test_sale_mrp_kit_bom.py | 58 +++++++++++++++++++ addons/sale_stock/models/sale_order_line.py | 2 +- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 82148aebca7..efc416ea578 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -522,7 +522,7 @@ class PurchaseOrderLine(models.Model): return { # truncate to 2000 to avoid triggering index limit error # TODO: remove index in master? - 'name': (self.name or '')[:2000], + 'name': (self.product_id.display_name or '')[:2000], 'product_id': self.product_id.id, 'date': date_planned, 'date_deadline': date_planned, diff --git a/addons/sale_mrp/tests/test_sale_mrp_kit_bom.py b/addons/sale_mrp/tests/test_sale_mrp_kit_bom.py index f1d796636a1..b711aa6db1d 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_kit_bom.py +++ b/addons/sale_mrp/tests/test_sale_mrp_kit_bom.py @@ -396,3 +396,61 @@ class TestSaleMrpKitBom(TransactionCase): for move_line in ship.move_line_ids: self.assertEqual(move_line.move_id.product_uom_qty, move_line.qty_done, "Quantity done should be equal to the quantity reserved in the move line") + + def test_kit_in_delivery_slip(self): + """ + Suppose this structure: + Sale order: + - Kit 1 with a sales description("test"): + |- Compo 1 + - Product 1 + This test ensures that, when delivering a Kit product with a sales description, + the delivery report is correctly printed with all the products. + """ + kit_1, component_1, product_1 = self.env['product.product'].create([{ + 'name': n, + 'type': 'product', + } for n in ['Kit 1', 'Compo 1', 'Product 1']]) + kit_1.description_sale = "test" + + self.env['mrp.bom'].create([{ + 'product_tmpl_id': kit_1.product_tmpl_id.id, + 'product_qty': 1, + 'type': 'phantom', + 'bom_line_ids': [ + (0, 0, {'product_id': component_1.id, 'product_qty': 1}), + ], + }]) + customer = self.env['res.partner'].create({ + 'name': 'customer', + }) + so = self.env['sale.order'].create({ + 'partner_id': customer.id, + 'order_line': [ + (0, 0, { + 'product_id': kit_1.id, + 'product_uom_qty': 1.0, + }), + (0, 0, { + 'product_id': product_1.id, + 'product_uom_qty': 1.0, + })], + }) + so.action_confirm() + picking = so.picking_ids + self.assertEqual(len(so.picking_ids.move_ids_without_package), 2) + picking.move_ids.quantity_done = 1 + picking.button_validate() + self.assertEqual(picking.state, 'done') + + html_report = self.env['ir.actions.report']._render_qweb_html('stock.report_deliveryslip', picking.ids)[0].decode('utf-8').split('\n') + keys = [ + "Kit 1", "Compo 1", + "Products not associated with a kit", "Product 1", + ] + for line in html_report: + if not keys: + break + if keys[0] in line: + keys = keys[1:] + self.assertFalse(keys, "All keys should be in the report with the defined order") diff --git a/addons/sale_stock/models/sale_order_line.py b/addons/sale_stock/models/sale_order_line.py index 7b43c9b974e..c9760b3c2fe 100644 --- a/addons/sale_stock/models/sale_order_line.py +++ b/addons/sale_stock/models/sale_order_line.py @@ -330,7 +330,7 @@ class SaleOrderLine(models.Model): procurements.append(self.env['procurement.group'].Procurement( line.product_id, product_qty, procurement_uom, line.order_id.partner_shipping_id.property_stock_customer, - line.name, line.order_id.name, line.order_id.company_id, values)) + line.product_id.display_name, line.order_id.name, line.order_id.company_id, values)) if procurements: self.env['procurement.group'].run(procurements)