From a73e69b2bb53fb8b6a84b0e9d42bea88961eeb2d Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Tue, 12 Apr 2022 15:29:35 +0000 Subject: [PATCH] [FIX] mrp, sale_mrp: set bom_line_id on all moves for kits Current behavior: When using 2 steps delivery and selling a kit product, not all moves had bom_line_id set. So if you go in the transfers you couldn't always see the "Kit" column in the operations. Steps to reproduce: - Activate 2 steps delivery - Create a Kit with 2 products - Create a quotation with kit and confirm it - Go in the delivery - In WH/Pick you can't see Kit column - In WH/Out you can see the Kit column opw-2796974 closes odoo/odoo#89371 X-original-commit: 88c3c3f49393af08e4070c0d2f5cccbec9096c1f Signed-off-by: William Henrotin (whe) Signed-off-by: Engels Robin (roen) --- addons/mrp/models/stock_move.py | 5 ++ .../sale_mrp/tests/test_sale_mrp_kit_bom.py | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index b314e9ab5c4..77660241770 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -542,3 +542,8 @@ class StockMove(models.Model): self.move_line_ids = self._set_quantity_done_prepare_vals(quantity_done) else: super()._multi_line_quantity_done_set(quantity_done) + + def _prepare_procurement_values(self): + res = super()._prepare_procurement_values() + res['bom_line_id'] = self.bom_line_id.id + return res 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 cfa1486c3ef..b3c2833b21b 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_kit_bom.py +++ b/addons/sale_mrp/tests/test_sale_mrp_kit_bom.py @@ -410,3 +410,56 @@ class TestSaleMrpKitBom(TransactionCase): # Checks the delivery amount (must be 1). self.assertEqual(so.order_line.qty_delivered, 1) + + def test_sale_kit_show_kit_in_delivery(self): + """Create a kit with 2 product and activate 2 steps + delivery and check that every stock move contains + a bom_line_id + """ + + wh = self.env['stock.warehouse'].search([('company_id', '=', self.env.user.id)], limit=1) + wh.write({'delivery_steps': 'pick_ship'}) + + kitA = self._create_product('Kit Product', 'product', 0.00) + compA = self._create_product('ComponentA', 'product', 0.00) + compB = self._create_product('ComponentB', 'product', 0.00) + + # Create BoM for KitB + bom_product_formA = Form(self.env['mrp.bom']) + bom_product_formA.product_id = kitA + bom_product_formA.product_tmpl_id = kitA.product_tmpl_id + bom_product_formA.product_qty = 1.0 + bom_product_formA.type = 'phantom' + with bom_product_formA.bom_line_ids.new() as bom_line: + bom_line.product_id = compA + bom_line.product_qty = 1 + with bom_product_formA.bom_line_ids.new() as bom_line: + bom_line.product_id = compB + bom_line.product_qty = 1 + bom_product_formA.save() + + customer = self.env['res.partner'].create({ + 'name': 'customer', + }) + + so = self.env['sale.order'].create({ + 'partner_id': customer.id, + 'order_line': [ + (0, 0, { + 'name': kitA.name, + 'product_id': kitA.id, + 'product_uom_qty': 1.0, + 'product_uom': kitA.uom_id.id, + 'price_unit': 1, + 'tax_id': False, + })] + }) + so.action_confirm() + + pick = so.picking_ids[0] + ship = so.picking_ids[1] + + self.assertTrue(pick.move_ids_without_package[0].bom_line_id, "All component from kits should have a bom line") + self.assertTrue(pick.move_ids_without_package[1].bom_line_id, "All component from kits should have a bom line") + self.assertTrue(ship.move_ids_without_package[0].bom_line_id, "All component from kits should have a bom line") + self.assertTrue(ship.move_ids_without_package[1].bom_line_id, "All component from kits should have a bom line")