From 9df79f42d0c0663bc1eee1958376231ca1623c2f Mon Sep 17 00:00:00 2001 From: William Henrotin Date: Tue, 2 Apr 2019 07:15:48 +0000 Subject: [PATCH] [IMP] mrp: manage actions without raw moves If a manufacturing order doens't have any raw move, it now triggers a user error in case of action_confirm and simply change it's state in case of cancel. Task: 1942231 Co-Authored-By: Hetal Dhanak --- addons/mrp/models/mrp_production.py | 5 +++++ addons/sale_mrp/tests/test_sale_mrp_procurement.py | 7 +++++++ 2 files changed, 12 insertions(+) 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'])