From e37ededc56290ea653d9d097fe818c68abc4d73b Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Tue, 19 Apr 2022 13:12:26 +0000 Subject: [PATCH] [FIX] mrp: stop all timers when cancelling work order MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Steps to reproduce the bug: - Create a manufacturing order to produce “Table” - Confirm and plan the MO - Start the work order - Cancel the MO Problem: - The work order is cancelled, but the timers continue to run. - "Block", "Unblock" and “Unplan" button should be hidden when MO is cancelled opw-2817842 closes odoo/odoo#89442 X-original-commit: 5682015958d03f4a65969afe3fce9b9b05e5b505 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/mrp/models/mrp_workorder.py | 1 + addons/mrp/tests/test_order.py | 18 ++++++++++++++++++ addons/mrp/views/mrp_production_views.xml | 2 +- addons/mrp/views/mrp_workorder_views.xml | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 7a85d10d996..4783a0879c8 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -657,6 +657,7 @@ class MrpWorkorder(models.Model): def action_cancel(self): self.leave_id.unlink() + self.end_all() return self.write({'state': 'cancel'}) def action_replan(self): diff --git a/addons/mrp/tests/test_order.py b/addons/mrp/tests/test_order.py index 6be0eca0919..87591b6c72f 100644 --- a/addons/mrp/tests/test_order.py +++ b/addons/mrp/tests/test_order.py @@ -2736,3 +2736,21 @@ class TestMrpOrder(TestMrpCommon): mo_2.action_confirm() mo_2.button_plan() self.assertEqual(mo_2.workorder_ids[0].workcenter_id.id, workcenter_2.id, 'workcenter_2 is faster than workcenter_1 to manufacture 4 units') + + def test_timers_after_cancelling_mo(self): + """ + Check that the timers in the workorders are stopped after the cancellation of the MO + """ + mo_form = Form(self.env['mrp.production']) + mo_form.bom_id = self.bom_2 + mo_form.product_qty = 1 + mo = mo_form.save() + mo.action_confirm() + mo.button_plan() + + wo = mo.workorder_ids + wo.button_start() + mo.action_cancel() + self.assertEqual(mo.state, 'cancel', 'Manufacturing order should be cancelled.') + self.assertEqual(wo.state, 'cancel', 'Workorders should be cancelled.') + self.assertTrue(mo.workorder_ids.time_ids.date_end, 'The timers must stop after the cancellation of the MO') diff --git a/addons/mrp/views/mrp_production_views.xml b/addons/mrp/views/mrp_production_views.xml index 11b4c8a4d98..ae0afb42029 100644 --- a/addons/mrp/views/mrp_production_views.xml +++ b/addons/mrp/views/mrp_production_views.xml @@ -110,7 +110,7 @@ confirm="There are no components to consume. Are you still sure you want to continue?"/>