From 58cef1f34ae2d5cdc166eeb3e206fe803e3b7218 Mon Sep 17 00:00:00 2001 From: Oihane Crucelaegui Date: Tue, 10 Sep 2024 15:25:54 +0200 Subject: [PATCH] [FIX] mrp_repair_cancel_reason: wizard does not launch + permissions + dependencies --- mrp_repair_cancel_reason/README.rst | 7 +- mrp_repair_cancel_reason/__manifest__.py | 12 +- mrp_repair_cancel_reason/i18n/es.po | 124 ++++++++++++++++++ .../i18n/mrp_repair_cancel_reason.pot | 124 ++++++++++++++++++ .../models/repair_order.py | 37 +++++- .../security/ir.model.access.csv | 5 +- .../tests/test_repair_order_cancel_reason.py | 36 ++--- .../views/repair_order_cancel_reason_view.xml | 9 +- .../views/repair_order_view.xml | 17 --- .../wizard/wiz_repair_order_cancel_reason.py | 26 ++-- .../wiz_repair_order_cancel_reason_view.xml | 4 +- 11 files changed, 333 insertions(+), 68 deletions(-) create mode 100644 mrp_repair_cancel_reason/i18n/es.po create mode 100644 mrp_repair_cancel_reason/i18n/mrp_repair_cancel_reason.pot diff --git a/mrp_repair_cancel_reason/README.rst b/mrp_repair_cancel_reason/README.rst index bded134..84373f6 100644 --- a/mrp_repair_cancel_reason/README.rst +++ b/mrp_repair_cancel_reason/README.rst @@ -2,9 +2,10 @@ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 -======================== -MRP repair cancel reason -======================== +==================== +Repair cancel reason +==================== + This module creates the new object "Repair Cancel Reason". When canceling a repair, we will display a wizard in which you have to select the "reason for cancellation". By confirming the wizard, the "reason for diff --git a/mrp_repair_cancel_reason/__manifest__.py b/mrp_repair_cancel_reason/__manifest__.py index 1153801..2e403b6 100644 --- a/mrp_repair_cancel_reason/__manifest__.py +++ b/mrp_repair_cancel_reason/__manifest__.py @@ -1,21 +1,15 @@ # (c) 2015 Alfredo de la Fuente - AvanzOSC # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html { - "name": "MRP Repair Cancel Reason", + "name": "Repair Cancel Reason", "version": "16.0.1.0.0", "license": "AGPL-3", "author": "AvanzOSC", "website": "https://github.com/avanzosc/mrp-repair-addons", - "contributors": [ - "Ana Juaristi ", - "Alfredo de la Fuente ", - ], - "category": "Manufacturing", + "category": "Inventory/Inventory", "depends": [ - "product", - "stock", - "mrp", "repair", + "stock", ], "data": [ "security/ir.model.access.csv", diff --git a/mrp_repair_cancel_reason/i18n/es.po b/mrp_repair_cancel_reason/i18n/es.po new file mode 100644 index 0000000..1c20843 --- /dev/null +++ b/mrp_repair_cancel_reason/i18n/es.po @@ -0,0 +1,124 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_repair_cancel_reason +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-10 12:49+0000\n" +"PO-Revision-Date: 2024-09-10 12:49+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_repair_cancel_reason +#: model:ir.model,name:mrp_repair_cancel_reason.model_wiz_repair_order_cancel_reason +msgid "Ask a reason from the repair cancellation" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "Cancel" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.view_repair_order_form_inh_cancel_reason +msgid "Cancel Repair" +msgstr "Cancelar reparación" + +#. module: mrp_repair_cancel_reason +#: model:repair.order.cancel.reason,name:mrp_repair_cancel_reason.mrp_cancel_reason_customer +msgid "Canceled at customer request" +msgstr "Cancelado por petición del cliente" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "" +"Choose the reason for the cancellation of the\n" +" repair." +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "Confirm" +msgstr "Confirmar" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__create_uid +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__create_date +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__create_date +msgid "Created on" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__display_name +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__id +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__id +msgid "ID" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason____last_update +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__write_uid +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__write_date +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__write_date +msgid "Last Updated on" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__name +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__reason_id +msgid "Reason" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order__cancel_reason_id +msgid "Reason for cancellation" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.actions.act_window,name:mrp_repair_cancel_reason.action_repair_order_cancel_with_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "Reason for the cancellation" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.actions.act_window,name:mrp_repair_cancel_reason.action_repair_order_cancel_reason +#: model:ir.model,name:mrp_repair_cancel_reason.model_repair_order_cancel_reason +#: model:ir.ui.menu,name:mrp_repair_cancel_reason.menu_repair_order_cancel_reason +msgid "Repair Cancel Reason" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model,name:mrp_repair_cancel_reason.model_repair_order +msgid "Repair Order" +msgstr "Orden de reparación" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "or" +msgstr "" diff --git a/mrp_repair_cancel_reason/i18n/mrp_repair_cancel_reason.pot b/mrp_repair_cancel_reason/i18n/mrp_repair_cancel_reason.pot new file mode 100644 index 0000000..132b263 --- /dev/null +++ b/mrp_repair_cancel_reason/i18n/mrp_repair_cancel_reason.pot @@ -0,0 +1,124 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mrp_repair_cancel_reason +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-10 12:49+0000\n" +"PO-Revision-Date: 2024-09-10 12:49+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mrp_repair_cancel_reason +#: model:ir.model,name:mrp_repair_cancel_reason.model_wiz_repair_order_cancel_reason +msgid "Ask a reason from the repair cancellation" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "Cancel" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.view_repair_order_form_inh_cancel_reason +msgid "Cancel Repair" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:repair.order.cancel.reason,name:mrp_repair_cancel_reason.mrp_cancel_reason_customer +msgid "Canceled at customer request" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "" +"Choose the reason for the cancellation of the\n" +" repair." +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "Confirm" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__create_uid +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__create_uid +msgid "Created by" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__create_date +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__create_date +msgid "Created on" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__display_name +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__display_name +msgid "Display Name" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__id +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__id +msgid "ID" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason____last_update +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__write_uid +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__write_date +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__write_date +msgid "Last Updated on" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order_cancel_reason__name +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_wiz_repair_order_cancel_reason__reason_id +msgid "Reason" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model.fields,field_description:mrp_repair_cancel_reason.field_repair_order__cancel_reason_id +msgid "Reason for cancellation" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.actions.act_window,name:mrp_repair_cancel_reason.action_repair_order_cancel_with_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "Reason for the cancellation" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.actions.act_window,name:mrp_repair_cancel_reason.action_repair_order_cancel_reason +#: model:ir.model,name:mrp_repair_cancel_reason.model_repair_order_cancel_reason +#: model:ir.ui.menu,name:mrp_repair_cancel_reason.menu_repair_order_cancel_reason +msgid "Repair Cancel Reason" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model:ir.model,name:mrp_repair_cancel_reason.model_repair_order +msgid "Repair Order" +msgstr "" + +#. module: mrp_repair_cancel_reason +#: model_terms:ir.ui.view,arch_db:mrp_repair_cancel_reason.wiz_repair_order_cancel_reason_form_view +msgid "or" +msgstr "" diff --git a/mrp_repair_cancel_reason/models/repair_order.py b/mrp_repair_cancel_reason/models/repair_order.py index 0f259dd..ad91d30 100644 --- a/mrp_repair_cancel_reason/models/repair_order.py +++ b/mrp_repair_cancel_reason/models/repair_order.py @@ -1,21 +1,52 @@ # (c) 2015 Alfredo de la Fuente - AvanzOSC # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from odoo import fields, models +from odoo import _, fields, models +from odoo.exceptions import UserError class MrpRepair(models.Model): _inherit = "repair.order" cancel_reason_id = fields.Many2one( - "repair.order.cancel.reason", + comodel_name="repair.order.cancel.reason", string="Reason for cancellation", readonly=True, + copy=False, ondelete="restrict", ) + def action_repair_cancel(self): + if any(operation.state == "done" for operation in self.mapped("operations")): + raise UserError( + _("You cannot cancel a repair order with done stock moves.") + ) + if any(repair.state == "done" for repair in self): + raise UserError(_("You cannot cancel a completed repair order.")) + if not all(repair.cancel_reason_id for repair in self): + action = self.env["ir.actions.actions"]._for_xml_id( + "mrp_repair_cancel_reason.action_repair_order_cancel_with_reason" + ) + action["context"] = dict(self._context, create=False) + return action + return super().action_repair_cancel() + + def action_repair_cancel_draft(self): + if self.filtered(lambda repair: repair.state != "cancel"): + raise UserError(_("Repair must be canceled in order to reset it to draft.")) + self.write( + { + "cancel_reason_id": False, + } + ) + return super().action_repair_cancel_draft() + class MrpRepairCancelReason(models.Model): _name = "repair.order.cancel.reason" _description = "Repair Cancel Reason" - name = fields.Char("Reason", required=True, translate=True) + name = fields.Char( + string="Reason", + required=True, + translate=True, + ) diff --git a/mrp_repair_cancel_reason/security/ir.model.access.csv b/mrp_repair_cancel_reason/security/ir.model.access.csv index e89ef10..b523ee9 100644 --- a/mrp_repair_cancel_reason/security/ir.model.access.csv +++ b/mrp_repair_cancel_reason/security/ir.model.access.csv @@ -1,3 +1,4 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -access_repair_order_cancel_reason_user,access_repair_order_cancel_reason user,model_repair_order_cancel_reason,mrp.group_mrp_user,1,0,0,0 -access_repair_order_cancel_reason_manager,access_repair_order_cancel_reason manager,model_repair_order_cancel_reason,mrp.group_mrp_manager,1,1,1,1 +access_repair_order_cancel_reason_user,access_repair_order_cancel_reason user,model_repair_order_cancel_reason,stock.group_stock_user,1,0,0,0 +access_repair_order_cancel_reason_manager,access_repair_order_cancel_reason manager,model_repair_order_cancel_reason,stock.group_stock_manager,1,1,1,1 +access_wiz_repair_order_cancel_reason,access_wiz_repair_order_cancel_reason,mrp_repair_cancel_reason.model_wiz_repair_order_cancel_reason,stock.group_stock_user,1,1,1,1 diff --git a/mrp_repair_cancel_reason/tests/test_repair_order_cancel_reason.py b/mrp_repair_cancel_reason/tests/test_repair_order_cancel_reason.py index 4ffdcab..84e6701 100644 --- a/mrp_repair_cancel_reason/tests/test_repair_order_cancel_reason.py +++ b/mrp_repair_cancel_reason/tests/test_repair_order_cancel_reason.py @@ -1,27 +1,29 @@ # (c) 2015 Alfredo de la Fuente - AvanzOSC # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -import openerp.tests.common as common +from odoo.tests import common, tagged + +@tagged("post_install", "-at_install") class TestMrpRepairCancelReason(common.TransactionCase): - def setUp(self): - super().setUp() - self.data_model = self.env["ir.model.data"] - self.repair_order_model = self.env["repair.order"] - self.wiz_model = self.env["wiz.repair.order.cancel.reason"] - self.product = self.env.ref("product.product_product_6") - self.warehouse = self.data_model.get_object("stock", "warehouse0") + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.data_model = cls.env["ir.model.data"] + cls.repair_order_model = cls.env["repair.order"] + cls.wiz_model = cls.env["wiz.repair.order.cancel.reason"] + cls.product = cls.env.ref("product.product_product_6") + cls.warehouse = cls.env["stock.warehouse"].search( + [("company_id", "=", cls.env.company.id)], limit=1 + ) vals = { - "product_id": self.product.id, - "location_id": self.warehouse.lot_stock_id.id, - "location_dest_id": self.warehouse.lot_stock_id.id, - "product_uom": self.product.uom_id.id, + "product_id": cls.product.id, + "location_id": cls.warehouse.lot_stock_id.id, + "product_uom": cls.product.uom_id.id, } - self.repair_order = self.repair_order_model.create(vals) - self.reason = self.env.ref( - "repair_order_cancel_reason.mrp_cancel_reason_customer" - ) + cls.repair_order = cls.repair_order_model.create(vals) + cls.reason = cls.env.ref("mrp_repair_cancel_reason.mrp_cancel_reason_customer") def test_wizard_cancel_draft_repair_with_reason(self): vals = {"reason_id": self.reason.id} @@ -37,7 +39,7 @@ def test_wizard_cancel_draft_repair_with_reason(self): ) def test_wizard_cancel_confirmed_repair_with_reason(self): - self.repair_order.signal_workflow("repair_confirm") + self.repair_order.action_repair_confirm() vals = {"reason_id": self.reason.id} wiz = self.wiz_model.create(vals) wiz.with_context(active_ids=[self.repair_order.id]).confirm_cancel() diff --git a/mrp_repair_cancel_reason/views/repair_order_cancel_reason_view.xml b/mrp_repair_cancel_reason/views/repair_order_cancel_reason_view.xml index 4d30147..fbb8f16 100644 --- a/mrp_repair_cancel_reason/views/repair_order_cancel_reason_view.xml +++ b/mrp_repair_cancel_reason/views/repair_order_cancel_reason_view.xml @@ -8,6 +8,7 @@ + repair.order.cancel.reason @@ -16,17 +17,17 @@ + Repair Cancel Reason repair.order.cancel.reason tree,form + + diff --git a/mrp_repair_cancel_reason/views/repair_order_view.xml b/mrp_repair_cancel_reason/views/repair_order_view.xml index 2ca40da..6b76f3a 100644 --- a/mrp_repair_cancel_reason/views/repair_order_view.xml +++ b/mrp_repair_cancel_reason/views/repair_order_view.xml @@ -7,23 +7,6 @@ - - True - - -