From eb76b725ed97c8c6640cd76ed262bb4ce27bbee9 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Fri, 25 Feb 2022 09:40:25 +0000 Subject: [PATCH] [FIX] mrp: prevent the unplan of a single work order Steps to reproduce the bug: Go to a work order that is ready or waiting, try manually changing the scheduled start or end date > save Problem: Traceback is triggered because when we modify the date, we check if the start date is before the end date. But we cannot compare a False with a date opw-2768054 closes odoo/odoo#85991 X-original-commit: 1768a072fd40d14dc8c402c3ccad9a6733460c03 Signed-off-by: William Henrotin (whe) Signed-off-by: Djamel Touati (otd) --- addons/mrp/i18n/mrp.pot | 8 ++++++++ addons/mrp/models/mrp_workorder.py | 3 +++ 2 files changed, 11 insertions(+) diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index 7cd620376fb..550db41f8ea 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -2184,6 +2184,14 @@ msgstr "" msgid "It has already been unblocked." msgstr "" +#. module: mrp +#: code:addons/mrp/models/mrp_workorder.py:0 +#, python-format +msgid "" +"It is not possible to unplan one single Work Order. You should unplan the " +"Manufacturing Order instead in order to unplan all the linked operations." +msgstr "" + #. module: mrp #: model:ir.model.fields,field_description:mrp.field_mrp_production__is_planned msgid "Its Operations are Planned" diff --git a/addons/mrp/models/mrp_workorder.py b/addons/mrp/models/mrp_workorder.py index 003a189de0c..f9f0f2a925e 100644 --- a/addons/mrp/models/mrp_workorder.py +++ b/addons/mrp/models/mrp_workorder.py @@ -252,6 +252,9 @@ class MrpWorkorder(models.Model): workorder.date_planned_finished = workorder.leave_id.date_to def _set_dates_planned(self): + if self.leave_id and (not self[0].date_planned_start or not self[0].date_planned_finished): + raise UserError(_("It is not possible to unplan one single Work Order. " + "You should unplan the Manufacturing Order instead in order to unplan all the linked operations.")) date_from = self[0].date_planned_start date_to = self[0].date_planned_finished self.mapped('leave_id').sudo().write({