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)