From 1e7671c119ebf98463270b6749a2048d3e3f6d5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Tue, 3 Jun 2025 00:59:05 +0200 Subject: [PATCH] [ADD] maintenance_create_requests_from_project_task: create add-on --- .../.gitignore | 2 + .../README.rst | 48 +++++ .../__init__.py | 4 + .../__manifest__.py | 41 ++++ .../i18n/fr.po | 182 ++++++++++++++++++ ...ance_create_requests_from_project_task.pot | 182 ++++++++++++++++++ .../models/__init__.py | 1 + .../models/project_task.py | 29 +++ .../security/ir.model.access.csv | 2 + .../views/project_task.xml | 22 +++ .../wizard/__init__.py | 1 + .../create_maintenance_requests_wizard.py | 98 ++++++++++ .../create_maintenance_requests_wizard.xml | 54 ++++++ 13 files changed, 666 insertions(+) create mode 100644 maintenance_create_requests_from_project_task/.gitignore create mode 100644 maintenance_create_requests_from_project_task/README.rst create mode 100644 maintenance_create_requests_from_project_task/__init__.py create mode 100644 maintenance_create_requests_from_project_task/__manifest__.py create mode 100644 maintenance_create_requests_from_project_task/i18n/fr.po create mode 100644 maintenance_create_requests_from_project_task/i18n/maintenance_create_requests_from_project_task.pot create mode 100644 maintenance_create_requests_from_project_task/models/__init__.py create mode 100644 maintenance_create_requests_from_project_task/models/project_task.py create mode 100644 maintenance_create_requests_from_project_task/security/ir.model.access.csv create mode 100644 maintenance_create_requests_from_project_task/views/project_task.xml create mode 100644 maintenance_create_requests_from_project_task/wizard/__init__.py create mode 100644 maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.py create mode 100644 maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.xml diff --git a/maintenance_create_requests_from_project_task/.gitignore b/maintenance_create_requests_from_project_task/.gitignore new file mode 100644 index 0000000..6da5887 --- /dev/null +++ b/maintenance_create_requests_from_project_task/.gitignore @@ -0,0 +1,2 @@ +*.*~ +*pyc diff --git a/maintenance_create_requests_from_project_task/README.rst b/maintenance_create_requests_from_project_task/README.rst new file mode 100644 index 0000000..470141b --- /dev/null +++ b/maintenance_create_requests_from_project_task/README.rst @@ -0,0 +1,48 @@ +============================================= +maintenance_create_requests_from_project_task +============================================= + +Allow the creation of multiple maintenance requests from a projet task. + +When user click on the button "Create maintenance requests", a wizard appears. +The wizard allows the user to configure the requests and to select the maintenance equipments concerned. +At wizard validation, one or several maintenance requests are created, one for each equipement selected. + +Installation +============ + +Use Odoo normal module installation procedure to install +``maintenance_create_requests_from_project_task``. + +Known issues / Roadmap +====================== + +None yet. + +Bug Tracker +=========== + +Bugs are tracked on `our issues website `_. In case of +trouble, please check there if your issue has already been +reported. If you spotted it first, help us smashing it by providing a +detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* Stéphan Sainléger + +Funders +------- + +The development of this module has been financially supported by: +* Elabore (https://elabore.coop) + + +Maintainer +---------- + +This module is maintained by Elabore. diff --git a/maintenance_create_requests_from_project_task/__init__.py b/maintenance_create_requests_from_project_task/__init__.py new file mode 100644 index 0000000..35e7c96 --- /dev/null +++ b/maintenance_create_requests_from_project_task/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizard diff --git a/maintenance_create_requests_from_project_task/__manifest__.py b/maintenance_create_requests_from_project_task/__manifest__.py new file mode 100644 index 0000000..91adf6c --- /dev/null +++ b/maintenance_create_requests_from_project_task/__manifest__.py @@ -0,0 +1,41 @@ +# Copyright 2023 Stéphan Sainléger (Elabore) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "maintenance_create_requests_from_project_task", + "version": "16.0.1.0.0", + "author": "Elabore", + "website": "https://elabore.coop", + "maintainer": "Stéphan Sainléger", + "license": "AGPL-3", + "category": "Tools", + "summary": "Allow the creation of multiple maintenance requests from a projet task.", + # any module necessary for this one to work correctly + "depends": [ + "base", + "maintenance", + "maintenance_project", + "project", + ], + "qweb": [ + # "static/src/xml/*.xml", + ], + "external_dependencies": { + "python": [], + }, + # always loaded + "data": [ + "security/ir.model.access.csv", + "views/project_task.xml", + "wizard/create_maintenance_requests_wizard.xml", + ], + # only loaded in demonstration mode + "demo": [], + "js": [], + "css": [], + "installable": True, + # Install this module automatically if all dependency have been previously + # and independently installed. Used for synergetic or glue modules. + "auto_install": False, + "application": False, +} diff --git a/maintenance_create_requests_from_project_task/i18n/fr.po b/maintenance_create_requests_from_project_task/i18n/fr.po new file mode 100644 index 0000000..230cb18 --- /dev/null +++ b/maintenance_create_requests_from_project_task/i18n/fr.po @@ -0,0 +1,182 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_create_requests_from_project_task +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-06-02 22:52+0000\n" +"PO-Revision-Date: 2025-06-03 00:58+0200\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: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Cancel" +msgstr "Annuler" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model,name:maintenance_create_requests_from_project_task.model_create_maintenance_requests_wizard +msgid "Configure the maintenance requests to create from the current task." +msgstr "Définir les données des demandes de maintenance à créer depuis la tâche actuelle." + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__maintenance_type__corrective +msgid "Corrective" +msgstr "Corrective" + +#. module: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Create" +msgstr "Créer" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.actions.act_window,name:maintenance_create_requests_from_project_task.action_create_maintenance_requests_wizard +msgid "Create Maintenance Requests" +msgstr "Créer des demandes de maintenance" + +#. module: maintenance_create_requests_from_project_task +#. odoo-python +#: code:addons/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.py:0 +#: model:ir.actions.server,name:maintenance_create_requests_from_project_task.task_wizard_action_create_maintenance_requests +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +#, python-format +msgid "Create maintenance requests" +msgstr "Créer des demandes de maintenance" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__create_uid +msgid "Created by" +msgstr "Créé par" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__create_date +msgid "Created on" +msgstr "Créé le" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__description +msgid "Description" +msgstr "Description" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__display_name +msgid "Display Name" +msgstr "Nom affiché" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__duration +msgid "Duration" +msgstr "Durée" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,help:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__duration +msgid "Duration in hours." +msgstr "Durée en heures." + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__equipment_domain +msgid "Equipment Domain" +msgstr "Domaine des équipements" + +#. module: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Equipments targetted" +msgstr "Équipements ciblés" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__3 +msgid "High" +msgstr "Élevé" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__id +msgid "ID" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard____last_update +msgid "Last Modified on" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__write_date +msgid "Last Updated on" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__1 +msgid "Low" +msgstr "Bas" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_project_task__maintenance_request_count +msgid "Maintenance Request Count" +msgstr "Nombre de demandes de maintenance" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_project_task__maintenance_request_ids +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.view_task_form2_maintenance_inherited +msgid "Maintenance Requests" +msgstr "Demandes de maintenance" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__maintenance_type +msgid "Maintenance Type" +msgstr "Type de maintenance" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__2 +msgid "Normal" +msgstr "Normal" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__maintenance_type__preventive +msgid "Preventive" +msgstr "Préventive" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__priority +msgid "Priority" +msgstr "Priorité" + +#. module: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Requests data" +msgstr "Données" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__schedule_date +msgid "Scheduled Date" +msgstr "Date prévue" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model,name:maintenance_create_requests_from_project_task.model_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__task_id +msgid "Task" +msgstr "Tâche" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__user_id +msgid "Technician" +msgstr "Technicien" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__name +msgid "Title" +msgstr "Nom" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__0 +msgid "Very Low" +msgstr "Très bas" diff --git a/maintenance_create_requests_from_project_task/i18n/maintenance_create_requests_from_project_task.pot b/maintenance_create_requests_from_project_task/i18n/maintenance_create_requests_from_project_task.pot new file mode 100644 index 0000000..46aa443 --- /dev/null +++ b/maintenance_create_requests_from_project_task/i18n/maintenance_create_requests_from_project_task.pot @@ -0,0 +1,182 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * maintenance_create_requests_from_project_task +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2025-06-02 22:52+0000\n" +"PO-Revision-Date: 2025-06-02 22:52+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: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Cancel" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model,name:maintenance_create_requests_from_project_task.model_create_maintenance_requests_wizard +msgid "Configure the maintenance requests to create from the current task." +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__maintenance_type__corrective +msgid "Corrective" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Create" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.actions.act_window,name:maintenance_create_requests_from_project_task.action_create_maintenance_requests_wizard +msgid "Create Maintenance Requests" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#. odoo-python +#: code:addons/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.py:0 +#: model:ir.actions.server,name:maintenance_create_requests_from_project_task.task_wizard_action_create_maintenance_requests +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +#, python-format +msgid "Create maintenance requests" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__create_uid +msgid "Created by" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__create_date +msgid "Created on" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__description +msgid "Description" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__display_name +msgid "Display Name" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__duration +msgid "Duration" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,help:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__duration +msgid "Duration in hours." +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__equipment_domain +msgid "Equipment Domain" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Equipments targetted" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__3 +msgid "High" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__id +msgid "ID" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard____last_update +msgid "Last Modified on" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__write_uid +msgid "Last Updated by" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__write_date +msgid "Last Updated on" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__1 +msgid "Low" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_project_task__maintenance_request_count +msgid "Maintenance Request Count" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_project_task__maintenance_request_ids +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.view_task_form2_maintenance_inherited +msgid "Maintenance Requests" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__maintenance_type +msgid "Maintenance Type" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__2 +msgid "Normal" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__maintenance_type__preventive +msgid "Preventive" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__priority +msgid "Priority" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model_terms:ir.ui.view,arch_db:maintenance_create_requests_from_project_task.create_maintenance_requests_wizard_view_form +msgid "Requests data" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__schedule_date +msgid "Scheduled Date" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model,name:maintenance_create_requests_from_project_task.model_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__task_id +msgid "Task" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__user_id +msgid "Technician" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields,field_description:maintenance_create_requests_from_project_task.field_create_maintenance_requests_wizard__name +msgid "Title" +msgstr "" + +#. module: maintenance_create_requests_from_project_task +#: model:ir.model.fields.selection,name:maintenance_create_requests_from_project_task.selection__create_maintenance_requests_wizard__priority__0 +msgid "Very Low" +msgstr "" diff --git a/maintenance_create_requests_from_project_task/models/__init__.py b/maintenance_create_requests_from_project_task/models/__init__.py new file mode 100644 index 0000000..edf2d36 --- /dev/null +++ b/maintenance_create_requests_from_project_task/models/__init__.py @@ -0,0 +1 @@ +from . import project_task diff --git a/maintenance_create_requests_from_project_task/models/project_task.py b/maintenance_create_requests_from_project_task/models/project_task.py new file mode 100644 index 0000000..4a0ab89 --- /dev/null +++ b/maintenance_create_requests_from_project_task/models/project_task.py @@ -0,0 +1,29 @@ +from odoo import fields, models, api + + +class ProjectTask(models.Model): + _inherit = "project.task" + + maintenance_request_ids = fields.One2many("maintenance.request", "task_id", string="Maintenance Requests") + maintenance_request_count = fields.Integer( + compute="_compute_maintenance_request_count" + ) + + @api.depends("maintenance_request_ids") + def _compute_maintenance_request_count(self): + for task in self: + task.maintenance_request_count = len( + task.maintenance_request_ids.filtered(lambda x: not x.stage_id.done) + ) + + def action_view_maintenance_request_ids(self): + """ + Access to the undone maintenance requests for this task + """ + self.ensure_one() + action = self.env["ir.actions.actions"]._for_xml_id( + "maintenance.hr_equipment_request_action" + ) + action["domain"] = [("task_id", "=", self.id), ("stage_id.done", "=", False)] + action["context"] = {"default_task_id": self.id} + return action diff --git a/maintenance_create_requests_from_project_task/security/ir.model.access.csv b/maintenance_create_requests_from_project_task/security/ir.model.access.csv new file mode 100644 index 0000000..8a0522e --- /dev/null +++ b/maintenance_create_requests_from_project_task/security/ir.model.access.csv @@ -0,0 +1,2 @@ +id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink +access_create_maintenance_requests_wizard,maintenance_create_requests_from_portal_tasks.create_maintenance_requests_wizard.access,model_create_maintenance_requests_wizard,base.group_user,1,1,1,0 \ No newline at end of file diff --git a/maintenance_create_requests_from_project_task/views/project_task.xml b/maintenance_create_requests_from_project_task/views/project_task.xml new file mode 100644 index 0000000..8bda432 --- /dev/null +++ b/maintenance_create_requests_from_project_task/views/project_task.xml @@ -0,0 +1,22 @@ + + + + project.task + + + + + + + + + + + diff --git a/maintenance_create_requests_from_project_task/wizard/__init__.py b/maintenance_create_requests_from_project_task/wizard/__init__.py new file mode 100644 index 0000000..2197c73 --- /dev/null +++ b/maintenance_create_requests_from_project_task/wizard/__init__.py @@ -0,0 +1 @@ +from . import create_maintenance_requests_wizard diff --git a/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.py b/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.py new file mode 100644 index 0000000..3f82981 --- /dev/null +++ b/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.py @@ -0,0 +1,98 @@ +from odoo import api, fields, models, _ +from odoo.tools.safe_eval import safe_eval + +class CreateMaintenanceRequestsWizard(models.TransientModel): + _name= "create.maintenance.requests.wizard" + _description= "Configure the maintenance requests to create from the current task." + + @api.model + def _default_task_id(self): + return self.env["project.task"].browse(self._context.get("active_ids")) + + + name = fields.Char("Title", required=True) + user_id = fields.Many2one('res.users', string='Technician') + priority = fields.Selection([('0', 'Very Low'), ('1', 'Low'), ('2', 'Normal'), ('3', 'High')], string='Priority') + maintenance_type = fields.Selection([('corrective', 'Corrective'), ('preventive', 'Preventive')], string='Maintenance Type', default="corrective") + schedule_date = fields.Datetime('Scheduled Date') + duration = fields.Float(help="Duration in hours.") + description = fields.Html('Description') + + equipment_domain = fields.Char("Equipment Domain") + + task_id = fields.Many2one( + "project.task", + string="Task", + required=True, + default=_default_task_id, + ) + + @api.model + def action_open_wizard(self): + """ + Open the form view. + """ + return { + 'name': _('Create maintenance requests'), + 'type': 'ir.actions.act_window', + 'res_model': 'create.maintenance.requests.wizard', + 'view_type': 'form', + 'view_mode': 'form', + 'target': 'new', + } + + + def create_maintenance_requests(self): + """ + Create the maintenance requests with the data filled in the wizard form. + """ + vals_list = self._compute_vals_list() + maintenance_requests = self.env["maintenance.request"].sudo().create(vals_list) + return self._get_action(maintenance_requests) + + + def _compute_vals_list(self): + """ + Compute the list of data to use for all the maintenance requests creation + """ + equipment_list = self.env["maintenance.equipment"].search(safe_eval(self.equipment_domain)) + if len(equipment_list) == 0: + raise UserError("No equipment is matching the domain. Maintenance request creation is not possible.") + + vals_list = [] + common_vals = { + "name": self.name, + "user_id": self.user_id.id, + "priority": self.priority, + "maintenance_type": self.maintenance_type, + "schedule_date": self.schedule_date, + "duration": self.duration, + "description": self.description, + "task_id": self.task_id.id, + "project_id": self.task_id.project_id.id + } + + for equipment in equipment_list: + vals = common_vals.copy() + vals["equipment_id"] = equipment.id + vals_list.append(vals) + + return vals_list + + + def _get_action(self, maintenance_requests): + """ + Provide the action to go to the tree view of the maintenance requests created. + """ + search_view_ref = self.env.ref('maintenance.hr_equipment_request_view_search', False) + form_view_ref = self.env.ref('maintenance.hr_equipment_request_view_form', False) + tree_view_ref = self.env.ref('maintenance.hr_equipment_request_view_tree', False) + + return { + 'domain': [('id', 'in', maintenance_requests.ids)], + 'name': 'Maintenance Requests', + 'res_model': 'maintenance.request', + 'type': 'ir.actions.act_window', + 'views': [(tree_view_ref.id, 'tree'), (form_view_ref.id, 'form')], + 'search_view_id': search_view_ref and [search_view_ref.id], + } diff --git a/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.xml b/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.xml new file mode 100644 index 0000000..843ddb6 --- /dev/null +++ b/maintenance_create_requests_from_project_task/wizard/create_maintenance_requests_wizard.xml @@ -0,0 +1,54 @@ + + + + create.maintenance.requests.wizard.view.form + create.maintenance.requests.wizard + +
+ + + + + + + + + + + + + + + + + +
+
+
+
+
+ + + Create Maintenance Requests + create.maintenance.requests.wizard + form + + new + + + + Create maintenance requests + + + code + action = model.action_open_wizard() + +