diff --git a/addons/mrp/models/stock_move.py b/addons/mrp/models/stock_move.py index ff5777651b1..ee11d7dd6e5 100644 --- a/addons/mrp/models/stock_move.py +++ b/addons/mrp/models/stock_move.py @@ -374,14 +374,14 @@ class StockMove(models.Model): # delete the move with original product which is not relevant anymore moves_ids_to_unlink.add(move.id) - move_to_unlink = self.env['stock.move'].browse(moves_ids_to_unlink).sudo() - move_to_unlink.quantity = 0 - move_to_unlink._action_cancel() - move_to_unlink.unlink() if phantom_moves_vals_list: phantom_moves = self.env['stock.move'].create(phantom_moves_vals_list) phantom_moves._adjust_procure_method() moves_ids_to_return |= phantom_moves.action_explode().ids + move_to_unlink = self.env['stock.move'].browse(moves_ids_to_unlink).sudo() + move_to_unlink.quantity = 0 + move_to_unlink._action_cancel() + move_to_unlink.unlink() return self.env['stock.move'].browse(moves_ids_to_return) def action_show_details(self): diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index a3a98b1b546..ead343bbe04 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -3616,3 +3616,31 @@ class TestMrpOrder(TestMrpCommon): warehouse.pbm_route_id.rule_ids.delay = 100 delays, _ = rule._get_lead_days(self.bom_1.product_id, bom=self.bom_1) self.assertEqual(delays['total_delay'], self.env.company.manufacturing_lead + self.bom_1.days_to_prepare_mo + self.bom_1.produce_delay + 100 * 2) + + def test_use_kit_as_component_in_production_without_bom(self): + """ + Test that a MO is not cancelled when a kit is added in a MO without a BoM. + """ + finished, component, kit = self.env['product.product'].create([{ + 'name': 'Product %s' % (i + 1), + 'type': 'product', + } for i in range(3)]) + self.env['mrp.bom'].create({ + 'product_id': kit.id, + 'product_tmpl_id': kit.product_tmpl_id.id, + 'type': 'phantom', + 'bom_line_ids': [(0, 0, { + 'product_id': component.id, + 'product_qty': 1, + })], + }) + + mo_form = Form(self.env['mrp.production']) + mo_form.product_id = finished + mo_form.product_qty = 1 + with mo_form.move_raw_ids.new() as line: + line.product_id = kit + mo = mo_form.save() + mo.action_confirm() + self.assertEqual(mo.state, 'confirmed') + self.assertEqual(mo.move_raw_ids.product_id, component)