From 6b8c367a1688eee77d45ed59a09bc9e9673a4381 Mon Sep 17 00:00:00 2001 From: "Touati Djamel (otd)" Date: Wed, 27 Oct 2021 13:12:32 +0000 Subject: [PATCH] [FIX] mrp: display a warning when archiving a used work center If a work center is used in any routing, a warning will be displayed when it will be archived opw-2658596 closes odoo/odoo#79185 X-original-commit: a05f4e05b9f4df88948ac3dfc1522828b63bfb64 Signed-off-by: Arnold Moyaux Signed-off-by: Djamel Touati (otd) --- addons/mrp/i18n/mrp.pot | 9 +++++++++ addons/mrp/models/mrp_workcenter.py | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/addons/mrp/i18n/mrp.pot b/addons/mrp/i18n/mrp.pot index 05c8ff8c6cc..d7ae482ae44 100644 --- a/addons/mrp/i18n/mrp.pot +++ b/addons/mrp/i18n/mrp.pot @@ -2871,6 +2871,15 @@ msgstr "" msgid "Not to restrict or prefer quants, but informative." msgstr "" +#. module: mrp +#: code:addons/mrp/models/mrp_workcenter.py:0 +#, python-format +msgid "" +"Note that archived work center(s): '%s' is/are still linked to active Bill " +"of Materials, which means that operations can still be planned on it/them. " +"To prevent this, deletion of the work center is recommended instead." +msgstr "" + #. module: mrp #: model:ir.model.fields,field_description:mrp.field_mrp_bom__message_needaction_counter #: model:ir.model.fields,field_description:mrp.field_mrp_production__message_needaction_counter diff --git a/addons/mrp/models/mrp_workcenter.py b/addons/mrp/models/mrp_workcenter.py index 94d220072b7..64a2c145495 100644 --- a/addons/mrp/models/mrp_workcenter.py +++ b/addons/mrp/models/mrp_workcenter.py @@ -265,6 +265,23 @@ class MrpWorkcenter(models.Model): remaining -= interval_minutes return False, 'Not available slot 700 days after the planned start' + def action_archive(self): + res = super().action_archive() + filtered_workcenters = ", ".join(workcenter.name for workcenter in self.filtered('routing_line_ids')) + if filtered_workcenters: + return { + 'type': 'ir.actions.client', + 'tag': 'display_notification', + 'params': { + 'title': _("Note that archived work center(s): '%s' is/are still linked to active Bill of Materials, which means that operations can still be planned on it/them. " + "To prevent this, deletion of the work center is recommended instead.", filtered_workcenters), + 'type': 'warning', + 'sticky': True, #True/False will display for few seconds if false + 'next': {'type': 'ir.actions.act_window_close'}, + }, + } + return res + class WorkcenterTag(models.Model): _name = 'mrp.workcenter.tag'