diff --git a/mrp_operations_extension/__openerp__.py b/mrp_operations_extension/__openerp__.py
index ccd188823..98cef199d 100644
--- a/mrp_operations_extension/__openerp__.py
+++ b/mrp_operations_extension/__openerp__.py
@@ -30,6 +30,7 @@
"data": [
"data/mrp_operations_extension_data.xml",
"wizard/mrp_workorder_produce_view.xml",
+ "wizard/workcerter_line_finish_view.xml",
"views/mrp_workcenter_view.xml",
"views/mrp_routing_operation_view.xml",
"views/mrp_production_view.xml",
diff --git a/mrp_operations_extension/models/mrp_production.py b/mrp_operations_extension/models/mrp_production.py
index 62036a677..a8473d813 100644
--- a/mrp_operations_extension/models/mrp_production.py
+++ b/mrp_operations_extension/models/mrp_production.py
@@ -137,3 +137,25 @@ class MrpProductionWorkcenterLine(models.Model):
# bypass force_production method in production order
workorder.production_id.state = 'in_production'
return super(MrpProductionWorkcenterLine, self).action_start_working()
+
+ @api.multi
+ def button_done(self):
+ res = {}
+ move_list = self.move_lines.filtered(
+ lambda x: x.state not in('cancel', 'done'))
+ if move_list:
+ idform = self.env.ref(
+ 'mrp_operations_extension.finish_wo_form_view')
+ res = {
+ 'type': 'ir.actions.act_window',
+ 'name': _('Finish WO'),
+ 'res_model': 'workcenter.line.finish',
+ 'view_type': 'form',
+ 'view_mode': 'form',
+ 'views': [(idform.id, 'form')],
+ 'target': 'new',
+ 'context': self.env.context
+ }
+ else:
+ self.signal_workflow('button_done')
+ return res
diff --git a/mrp_operations_extension/tests/test_mrp_operations_extension.py b/mrp_operations_extension/tests/test_mrp_operations_extension.py
index f5388fbcc..df908c820 100644
--- a/mrp_operations_extension/tests/test_mrp_operations_extension.py
+++ b/mrp_operations_extension/tests/test_mrp_operations_extension.py
@@ -42,6 +42,7 @@ class TestMrpOperationsExtension(common.TransactionCase):
self.produce_line_model = self.env['mrp.product.produce.line']
self.production = self.env.ref(
'mrp_operations_extension.mrp_production_opeext')
+ self.workcenter_line_finish = self.env['workcenter.line.finish']
def test_check_do_production_mrp_routing(self):
# None of the workcenter lines have the check marked
@@ -188,3 +189,44 @@ class TestMrpOperationsExtension(common.TransactionCase):
self.assertEqual(
line.state, 'done',
'Error work center line not in done state')
+
+ def test_operation_button_done(self):
+ self.production.signal_workflow('button_confirm')
+ workorder = self.production.workcenter_lines[0]
+ workorder.action_assign()
+ workorder.force_assign()
+ workorder.signal_workflow('button_start_working')
+ res = workorder.button_done()
+ if res: # check make_them_done
+ lines2move = len(workorder.move_lines.filtered(
+ lambda x: x.state not in ('done')))
+ self.workcenter_line_finish.with_context(
+ active_id=workorder.id,
+ active_model='mrp.production.workcenter.line').make_them_done()
+ lines_done = len(workorder.move_lines.filtered(
+ lambda x: x.state in ('done')))
+ self.assertEqual(lines2move, lines_done,
+ 'Error work order moves quantity do not match')
+ self.assertEqual(workorder.state, 'done',
+ 'Error work center line not in done state')
+ workorder1 = self.production.workcenter_lines[1]
+ workorder1.signal_workflow('button_start_working')
+ res1 = workorder1.button_done()
+ self.assertFalse(res1, 'Error there are pending movements')
+ workorder2 = self.production.workcenter_lines[2]
+ workorder2.action_assign()
+ workorder2.force_assign()
+ workorder2.signal_workflow('button_start_working')
+ res2 = workorder2.button_done()
+ if res2: # check cancel_all
+ lines2move2 = len(workorder2.move_lines.filtered(
+ lambda x: x.state not in ('cancel')))
+ self.workcenter_line_finish.with_context(
+ active_id=workorder2.id,
+ active_model='mrp.production.workcenter.line').cancel_all()
+ lines_cancel = len(workorder2.move_lines.filtered(
+ lambda x: x.state in ('cancel')))
+ self.assertEqual(lines2move2, lines_cancel,
+ 'Error work order moves quantity do not match')
+ self.assertEqual(workorder2.state, 'done',
+ 'Error work center line not in done state')
diff --git a/mrp_operations_extension/views/mrp_production_view.xml b/mrp_operations_extension/views/mrp_production_view.xml
index 8404851c6..43277c3a0 100644
--- a/mrp_operations_extension/views/mrp_production_view.xml
+++ b/mrp_operations_extension/views/mrp_production_view.xml
@@ -118,6 +118,7 @@