diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index f6aef3a9456..cadff6c8b2f 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -97,7 +97,11 @@ class StockRule(models.Model): # Create now the procurement group that will be assigned to the new MO # This ensure that the outgoing move PostProduction -> Stock is linked to its MO # rather than the original record (MO or SO) - procurement.values['group_id'] = self.env["procurement.group"].create({'name': name}) + group = procurement.values.get('group_id') + if group: + procurement.values['group_id'] = group.copy({'name': name}) + else: + procurement.values['group_id'] = self.env["procurement.group"].create({'name': name}) return super()._run_pull(procurements) def _get_custom_move_fields(self): diff --git a/addons/sale_mrp/tests/test_multistep_manufacturing.py b/addons/sale_mrp/tests/test_multistep_manufacturing.py index 3eb709cdc33..e9d4b2af209 100644 --- a/addons/sale_mrp/tests/test_multistep_manufacturing.py +++ b/addons/sale_mrp/tests/test_multistep_manufacturing.py @@ -133,3 +133,20 @@ class TestMultistepManufacturing(TestMrpCommon): exception = self.env['mail.activity'].search([('res_model', '=', 'mrp.production'), ('res_id', '=', manufaturing_from_so.id)]) self.assertEqual(len(exception.ids), 1, 'When user cancelled child manufacturing, exception must be generated on parent manufacturing.') + + def test_manufacturing_step_three(self): + """ Testing for Step-3 """ + with Form(self.warehouse) as warehouse: + warehouse.manufacture_steps = 'pbm_sam' + self.sale_order.action_confirm() + + mo = self.env['mrp.production'].search([ + ('origin', '=', self.sale_order.name), + ('product_id', '=', self.product_manu.id), + ]) + + self.assertEqual(self.sale_order.mrp_production_count, 1) + self.assertEqual(mo.sale_order_count, 1) + + self.assertEqual(self.sale_order.action_view_mrp_production()['res_id'], mo.id) + self.assertEqual(mo.action_view_sale_orders()['res_id'], self.sale_order.id)