From 2a19948833769c174e9acf6047378380a47072a9 Mon Sep 17 00:00:00 2001 From: Adrien Widart Date: Mon, 15 Nov 2021 12:38:58 +0000 Subject: [PATCH] [FIX] mrp: configure in and out moves of draft MO In multi steps configurations, the additional products of a MO could be missing in the associated picking To reproduce the issue: (Use demo data) 1. In Settings, enable "Multi-Step Routes" 2. Update the current warehouse: - Manufacture: 2 steps 3. Create a MO for product "Table Top" 4. Edit the MO: - Add 1 x Screw in the components 5. Confirm the MO 6. Open the generated Picking Error: The operations only contains one line for "Wood Panel". There should be a second line for the "Screw" When adding the new component, a new stock move is created but the latter does not have any `group_id` defined. This is the reason why the generated picking does not include this stock move. OPW-2671995 closes odoo/odoo#79894 X-original-commit: 720f29fc6b7626ae734187242870a27065441ac2 Signed-off-by: William Henrotin (whe) Signed-off-by: Adrien Widart --- addons/mrp/models/stock_move.py | 3 ++ .../test_warehouse_multistep_manufacturing.py | 29 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index 38577c2b640..508d5e65740 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -237,6 +237,9 @@ class StockMove(models.Model): defaults['state'] = 'done' defaults['additional'] = True defaults['product_uom_qty'] = 0.0 + elif production_id.state == 'draft': + defaults['group_id'] = production_id.procurement_group_id.id + defaults['reference'] = production_id.name return defaults def write(self, vals): diff --git a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py index 7338720a6c7..1053701864c 100644 --- a/addons/mrp/tests/test_warehouse_multistep_manufacturing.py +++ b/addons/mrp/tests/test_warehouse_multistep_manufacturing.py @@ -444,3 +444,32 @@ class TestMultistepManufacturingWarehouse(TestMrpCommon): [('product_id', '=', self.wood_product.id)]) self.assertTrue(pickings_component) self.assertTrue(rr_finish.name in pickings_component.origin) + + def test_2_steps_and_additional_moves(self): + """ Suppose a 2-steps configuration. If a user adds a product to an existing draft MO and then + confirms it, the associated picking should includes this new product""" + self.warehouse.manufacture_steps = 'pbm' + + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = self.bom.product_id + mo_form.picking_type_id = self.warehouse.manu_type_id + mo = mo_form.save() + + component_move = mo.move_raw_ids[0] + mo.with_context(default_raw_material_production_id=mo.id).move_raw_ids = [ + [0, 0, { + 'location_id': component_move.location_id.id, + 'location_dest_id': component_move.location_dest_id.id, + 'picking_type_id': component_move.picking_type_id.id, + 'product_id': self.product_2.id, + 'name': self.product_2.display_name, + 'product_uom_qty': 1, + 'product_uom': self.product_2.uom_id.id, + 'warehouse_id': component_move.warehouse_id.id, + 'raw_material_production_id': mo.id, + }] + ] + + mo.action_confirm() + + self.assertEqual(self.bom.bom_line_ids.product_id + self.product_2, mo.picking_ids.move_ids.product_id)