[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 <hdh-odoo@users.noreply.github.com>
This commit is contained in:
William Henrotin
2019-04-02 08:33:17 +00:00
co-authored by Hetal Dhanak
parent ab215ca158
commit 9df79f42d0
2 changed files with 12 additions and 0 deletions
+5
View File
@@ -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 = {}
@@ -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'])