diff --git a/addons/mrp/models/mrp_production.py b/addons/mrp/models/mrp_production.py index 5c5dd19a6d2..46dcaf6e49a 100644 --- a/addons/mrp/models/mrp_production.py +++ b/addons/mrp/models/mrp_production.py @@ -585,6 +585,8 @@ class MrpProduction(models.Model): def action_confirm(self): for production in self: + if not production.move_raw_ids: + raise UserError(_("Add some materials to consume before marking this MO as to do.")) for move_raw in production.move_raw_ids: move_raw.write({ 'group_id': production.procurement_group_id.id, @@ -761,6 +763,9 @@ class MrpProduction(models.Model): def action_cancel(self): """ Cancels production order, unfinished stock moves and set procurement orders in exception """ + if not self.move_raw_ids: + self.state = 'cancel' + return True if any(workorder.state == 'progress' for workorder in self.mapped('workorder_ids')): raise UserError(_('You can not cancel production order, a work order is still in progress.')) documents = {} diff --git a/addons/sale_mrp/tests/test_sale_mrp_procurement.py b/addons/sale_mrp/tests/test_sale_mrp_procurement.py index e6f947d7bad..a0ddbb749db 100644 --- a/addons/sale_mrp/tests/test_sale_mrp_procurement.py +++ b/addons/sale_mrp/tests/test_sale_mrp_procurement.py @@ -40,8 +40,15 @@ class TestSaleMrpProcurement(TransactionCase): product.route_ids.add(warehouse0.mto_pull_id.route_id) product_template_slidermobile0 = product.save() + product_component = Form(self.env['product.product']) + product_component.name = 'Battery' + product_product_bettery = product_component.save() + with Form(self.env['mrp.bom']) as bom: bom.product_tmpl_id = product_template_slidermobile0 + with bom.bom_line_ids.new() as line: + line.product_id = product_product_bettery + line.product_qty = 4 # I create a sale order for product Slider mobile so_form = Form(self.env['sale.order'])