From e5aa66efd7f2781b7a71366c7a5aa2c070713655 Mon Sep 17 00:00:00 2001 From: Meritxell Abellan Date: Fri, 20 Dec 2024 11:36:05 +0100 Subject: [PATCH] [IMP] mrp_production_back_to_draft: workorders back to draft Now workorders are reset when an MO gets back to draft --- mrp_production_back_to_draft/README.rst | 1 + .../models/mrp_production.py | 1 + .../readme/CONTRIBUTORS.md | 1 + .../static/description/index.html | 1 + .../tests/test_mrp_return_to_draft.py | 23 ++++++++++++++++++- 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mrp_production_back_to_draft/README.rst b/mrp_production_back_to_draft/README.rst index fa3c717f7..37c781d3f 100644 --- a/mrp_production_back_to_draft/README.rst +++ b/mrp_production_back_to_draft/README.rst @@ -57,6 +57,7 @@ Contributors ------------ - David Jiménez +- Meritxell Abellan Maintainers ----------- diff --git a/mrp_production_back_to_draft/models/mrp_production.py b/mrp_production_back_to_draft/models/mrp_production.py index 500d6e4a7..1b79e1ba5 100644 --- a/mrp_production_back_to_draft/models/mrp_production.py +++ b/mrp_production_back_to_draft/models/mrp_production.py @@ -22,6 +22,7 @@ class MrpProduction(models.Model): else: (rec.move_raw_ids + rec.move_finished_ids)._action_cancel() (rec.move_raw_ids + rec.move_finished_ids).write({"state": "draft"}) + rec.workorder_ids.write({"state": "waiting"}) if rec.state != "draft": raise UserError( _("Could not set the production order back to draft") diff --git a/mrp_production_back_to_draft/readme/CONTRIBUTORS.md b/mrp_production_back_to_draft/readme/CONTRIBUTORS.md index ac18283b8..c172ebacf 100644 --- a/mrp_production_back_to_draft/readme/CONTRIBUTORS.md +++ b/mrp_production_back_to_draft/readme/CONTRIBUTORS.md @@ -1 +1,2 @@ - David Jiménez \<\> +- Meritxell Abellan \<\> diff --git a/mrp_production_back_to_draft/static/description/index.html b/mrp_production_back_to_draft/static/description/index.html index 9cd9f74e0..4a652a565 100644 --- a/mrp_production_back_to_draft/static/description/index.html +++ b/mrp_production_back_to_draft/static/description/index.html @@ -402,6 +402,7 @@ If you spotted it first, help us to smash it by providing a detailed and welcome

Contributors

diff --git a/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py b/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py index 1505b7598..a770deb53 100644 --- a/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py +++ b/mrp_production_back_to_draft/tests/test_mrp_return_to_draft.py @@ -61,27 +61,48 @@ class TestMrpProductionAutovalidate(common.TransactionCase): "bom_id": cls.test_bom_1.id, } ) + cls.workcenter_id = cls.env["mrp.workcenter"].create( + { + "name": "Workcenter 01", + } + ) + cls.test_workorder_1 = cls.env["mrp.workorder"].create( + { + "name": "Workorder Test", + "product_uom_id": cls.prod_tp1.uom_id.id, + "production_id": cls.mo_1.id, + "workcenter_id": cls.workcenter_id.id, + "qty_remaining": 1, + "qty_produced": 0, + } + ) def test_01_mrp_return_to_draft(self): self.env["stock.quant"]._update_available_quantity( self.prod_ti1, self.location, 2 ) self.assertEqual(self.mo_1.state, "draft") + self.assertEqual(self.mo_1.workorder_ids.state, "waiting") self.mo_1._compute_move_raw_ids() self.mo_1.action_confirm() self.assertEqual(self.mo_1.state, "confirmed") + self.assertEqual(self.mo_1.workorder_ids.state, "ready") self.mo_1.action_return_to_draft() self.assertEqual(self.mo_1.state, "draft") + self.assertEqual(self.mo_1.workorder_ids.state, "waiting") self.mo_1._compute_move_raw_ids() self.mo_1.action_confirm() self.assertEqual(self.mo_1.state, "confirmed") + self.assertEqual(self.mo_1.workorder_ids.state, "ready") self.mo_1.action_cancel() self.assertEqual(self.mo_1.state, "cancel") + self.assertEqual(self.mo_1.workorder_ids.state, "cancel") self.mo_1.action_return_to_draft() self.assertEqual(self.mo_1.state, "draft") + self.assertNotIn(self.mo_1.workorder_ids.state, ["cancel"]) self.mo_1._compute_move_raw_ids() self.mo_1.action_confirm() self.mo_1.qty_producing = 2 - self.assertEqual(self.mo_1.state, "to_close") + self.mo_1.workorder_ids.action_mark_as_done() with self.assertRaises(UserError): self.mo_1.action_return_to_draft()