From d7d634c4b23677cf854715d1487aefc83d042ac8 Mon Sep 17 00:00:00 2001 From: Daniel-CA Date: Fri, 22 Jan 2016 11:30:47 +0100 Subject: [PATCH] [IMP] mrp_operations_extension: New behaviour added when finishing WO and there are pending movements --- mrp_operations_extension/__openerp__.py | 1 + .../models/mrp_production.py | 22 ++++++++++ .../tests/test_mrp_operations_extension.py | 42 +++++++++++++++++++ .../views/mrp_production_view.xml | 15 +++++++ mrp_operations_extension/wizard/__init__.py | 1 + .../wizard/workcenter_line_finish.py | 36 ++++++++++++++++ .../wizard/workcerter_line_finish_view.xml | 26 ++++++++++++ 7 files changed, 143 insertions(+) create mode 100644 mrp_operations_extension/wizard/workcenter_line_finish.py create mode 100644 mrp_operations_extension/wizard/workcerter_line_finish_view.xml 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 58958f045..8459d11f7 100644 --- a/mrp_operations_extension/models/mrp_production.py +++ b/mrp_operations_extension/models/mrp_production.py @@ -135,3 +135,25 @@ class MrpProductionWorkcenterLine(models.Model): if workorder.production_id.state in ('confirmed', 'ready'): 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 @@ diff --git a/mrp_operations_extension/wizard/__init__.py b/mrp_operations_extension/wizard/__init__.py index 79cfe897f..b04550b49 100644 --- a/mrp_operations_extension/wizard/__init__.py +++ b/mrp_operations_extension/wizard/__init__.py @@ -3,3 +3,4 @@ # For copyright and license notices, see __openerp__.py file in root directory ############################################################################## from . import mrp_work_order_produce +from . import workcenter_line_finish diff --git a/mrp_operations_extension/wizard/workcenter_line_finish.py b/mrp_operations_extension/wizard/workcenter_line_finish.py new file mode 100644 index 000000000..23e17efee --- /dev/null +++ b/mrp_operations_extension/wizard/workcenter_line_finish.py @@ -0,0 +1,36 @@ +# -*- coding: utf-8 -*- +############################################################################## +# For copyright and license notices, see __openerp__.py file in root directory +############################################################################## +from openerp import models, api + + +class WorkcenterLineFinish(models.TransientModel): + _name = "workcenter.line.finish" + + @api.multi + def make_them_done(self): + if ('active_id' in self.env.context and + (self.env.context['active_model'] == + 'mrp.production.workcenter.line')): + wc_line_obj = self.env['mrp.production.workcenter.line'] + wc_line = wc_line_obj.browse(self.env.context['active_id']) + wc_line.move_lines.filtered( + lambda x: x.state not in ('cancel', 'done')).action_done() + wc_line.signal_workflow('button_done') + + @api.multi + def cancel_all(self): + if ('active_id' in self.env.context and + (self.env.context['active_model'] == + 'mrp.production.workcenter.line')): + wc_line_obj = self.env['mrp.production.workcenter.line'] + wc_line = wc_line_obj.browse(self.env.context['active_id']) + wc_line.move_lines.filtered( + lambda x: x.state not in ('cancel', 'done')).action_cancel() + if wc_line.do_production: + wc_line.production_id.move_created_ids.filtered( + lambda x: x.state not in + ('cancel', 'done')).action_cancel() + wc_line.production_id.refresh() + wc_line.signal_workflow('button_done') diff --git a/mrp_operations_extension/wizard/workcerter_line_finish_view.xml b/mrp_operations_extension/wizard/workcerter_line_finish_view.xml new file mode 100644 index 000000000..9d1b549de --- /dev/null +++ b/mrp_operations_extension/wizard/workcerter_line_finish_view.xml @@ -0,0 +1,26 @@ + + + + + finish.wo.form.view + workcenter.line.finish + +
+ + + +
+
+
+