diff --git a/maintenance_project/README.rst b/maintenance_project/README.rst index 32a2fb9d3..5167d1cd2 100644 --- a/maintenance_project/README.rst +++ b/maintenance_project/README.rst @@ -30,7 +30,7 @@ Maintenance Projects This module extends the functionality of Odoo Maintenance module adding this features: -- Adds a project to an equipment. The project can be automatically created from the equipment definition. +- Adds a project to an equipment. You can link an existing project or create a new one (with the Create project button) after creating the equipment. - Adds project and task to a maintenance request. The default project for a request will be the equipment one, including the preventive requests periodically created. This is is a technical addon to allow timesheet assignment to a maintenance request. diff --git a/maintenance_project/__manifest__.py b/maintenance_project/__manifest__.py index 3ac777887..1051d538e 100644 --- a/maintenance_project/__manifest__.py +++ b/maintenance_project/__manifest__.py @@ -10,7 +10,6 @@ "website": "https://github.com/OCA/maintenance", "depends": ["base_maintenance", "project"], "data": [ - "security/maintenance_project_security.xml", "views/maintenance_equipment_views.xml", "views/maintenance_request_views.xml", "views/project_project_views.xml", diff --git a/maintenance_project/data/demo_maintenance_project.xml b/maintenance_project/data/demo_maintenance_project.xml index d41b6febd..a7f83eaa3 100644 --- a/maintenance_project/data/demo_maintenance_project.xml +++ b/maintenance_project/data/demo_maintenance_project.xml @@ -21,7 +21,6 @@ S/N 1 MODEL1 - @@ -36,7 +35,6 @@ S/N 2 MODEL2 - @@ -53,6 +51,10 @@ S/N 3 MODEL3 - + diff --git a/maintenance_project/models/maintenance_equipment.py b/maintenance_project/models/maintenance_equipment.py index 27c050118..cde8a9def 100644 --- a/maintenance_project/models/maintenance_equipment.py +++ b/maintenance_project/models/maintenance_equipment.py @@ -1,31 +1,27 @@ # Copyright 2019 Solvos Consultoría Informática () +# Copyright 2024 Tecnativa - Víctor Martínez # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from odoo import api, fields, models +from odoo import fields, models class MaintenanceEquipment(models.Model): _inherit = "maintenance.equipment" project_id = fields.Many2one(comodel_name="project.project", ondelete="restrict") - create_project_from_equipment = fields.Boolean(default=True) preventive_default_task_id = fields.Many2one( string="Default Task", comodel_name="project.task" ) - @api.model_create_multi - def create(self, vals_list): - project_obj = self.env["project.project"] - for values in vals_list: - if values.get("create_project_from_equipment"): - new_project = project_obj.create( - self._prepare_project_from_equipment_values(values) - ) - values["project_id"] = new_project.id - return super().create(vals_list) + def action_create_project(self): + self.ensure_one() + if not self.project_id: + self.project_id = self.env["project.project"].create( + self._prepare_project_from_equipment_values() + ) - def _prepare_project_from_equipment_values(self, values): + def _prepare_project_from_equipment_values(self): """ Default project data creation hook """ - return {"name": values.get("name")} + return {"name": self.name} diff --git a/maintenance_project/readme/DESCRIPTION.rst b/maintenance_project/readme/DESCRIPTION.rst index 060abd8f9..b151978ff 100644 --- a/maintenance_project/readme/DESCRIPTION.rst +++ b/maintenance_project/readme/DESCRIPTION.rst @@ -1,6 +1,6 @@ This module extends the functionality of Odoo Maintenance module adding this features: -- Adds a project to an equipment. The project can be automatically created from the equipment definition. +- Adds a project to an equipment. You can link an existing project or create a new one (with the Create project button) after creating the equipment. - Adds project and task to a maintenance request. The default project for a request will be the equipment one, including the preventive requests periodically created. This is is a technical addon to allow timesheet assignment to a maintenance request. diff --git a/maintenance_project/security/maintenance_project_security.xml b/maintenance_project/security/maintenance_project_security.xml deleted file mode 100644 index 14b6f309a..000000000 --- a/maintenance_project/security/maintenance_project_security.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/maintenance_project/static/description/index.html b/maintenance_project/static/description/index.html index e52cd904f..ada808b70 100644 --- a/maintenance_project/static/description/index.html +++ b/maintenance_project/static/description/index.html @@ -1,4 +1,3 @@ - @@ -372,7 +371,7 @@

Maintenance Projects

Beta License: AGPL-3 OCA/maintenance Translate me on Weblate Try me on Runboat

This module extends the functionality of Odoo Maintenance module adding this features:

    -
  • Adds a project to an equipment. The project can be automatically created from the equipment definition.
  • +
  • Adds a project to an equipment. You can link an existing project or create a new one (with the Create project button) after creating the equipment.
  • Adds project and task to a maintenance request. The default project for a request will be the equipment one, including the preventive requests periodically created.

This is is a technical addon to allow timesheet assignment to a maintenance request.

diff --git a/maintenance_project/tests/test_maintenance_project.py b/maintenance_project/tests/test_maintenance_project.py index 6ed884f0e..90218bf06 100644 --- a/maintenance_project/tests/test_maintenance_project.py +++ b/maintenance_project/tests/test_maintenance_project.py @@ -1,22 +1,33 @@ # Copyright 2019 Solvos Consultor??a Inform??tica () +# Copyright 2024 Tecnativa - Víctor Martínez # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -import odoo.tests.common as test_common +from odoo.tests import Form, new_test_user +from odoo.tests.common import users +from odoo.addons.base.tests.common import BaseCommon -class TestMaintenanceProject(test_common.TransactionCase): + +class TestMaintenanceProject(BaseCommon): @classmethod def setUpClass(cls): - super(TestMaintenanceProject, cls).setUpClass() - + super().setUpClass() cls.cron = cls.env.ref("maintenance.maintenance_requests_cron") cls.project1 = cls.env["project.project"].create({"name": "My project"}) - cls.project_demo1 = cls.env.ref("maintenance_project.project_project_1") - + cls.project_demo = cls.env.ref("maintenance_project.project_project_1") + new_test_user( + cls.env, + login="test-user", + groups="maintenance.group_equipment_manager,project.group_project_user", + ) + new_test_user( + cls.env, + login="test-project_manager-user", + groups="maintenance.group_equipment_manager,project.group_project_manager", + ) cls.equipment1 = cls.env["maintenance.equipment"].create( { "name": "My equipment", - "create_project_from_equipment": True, "maintenance_team_id": cls.env.ref( "maintenance.equipment_team_metrology" ).id, @@ -27,50 +38,64 @@ def setUpClass(cls): cls.equipment2 = cls.env["maintenance.equipment"].create( { "name": "My equipment without project", - "create_project_from_equipment": False, } ) cls.equipment3 = cls.env["maintenance.equipment"].create( { "name": "My equipment with related project", - "create_project_from_equipment": False, "project_id": cls.project1.id, } ) + cls.equipment_demo = cls.env.ref("maintenance_project.equipment_3") - cls.equipment_demo1 = cls.env.ref("maintenance_project.equipment_1") - cls.equipment_demo2 = cls.env.ref("maintenance_project.equipment_2") - cls.equipment_demo3 = cls.env.ref("maintenance_project.equipment_3") - - def test_maintenance_equipment_project(self): - self.assertEqual(self.equipment1.name, self.equipment1.project_id.name) + def test_maintenance_equipment_project_misc(self): + self.assertFalse(self.equipment1.project_id) self.assertFalse(self.equipment2.project_id) self.assertEqual(self.equipment3.project_id, self.project1) - self.assertEqual( - self.equipment_demo3.name, self.equipment_demo3.project_id.name + self.assertEqual(self.equipment_demo.name, self.equipment_demo.project_id.name) + + @users("test-project_manager-user") + def test_maintenance_equipment_project_admin(self): + equipment_a = self.env["maintenance.equipment"].create( + { + "name": "Test equipment A", + } + ) + self.assertFalse(equipment_a.project_id) + equipment_a.action_create_project() + self.assertTrue(equipment_a.project_id) + self.assertEqual(equipment_a.name, equipment_a.project_id.name) + equipment_b = self.env["maintenance.equipment"].create( + { + "name": "Test equipment b", + "project_id": self.project1.id, + } ) + self.assertEqual(equipment_b.project_id, self.project1) + equipment_b.action_create_project() + self.assertEqual(equipment_b.project_id, self.project1) def test_project_equipment_count(self): + self.equipment1.action_create_project() self.assertEqual(self.project1.equipment_count, 1) self.assertEqual(self.equipment1.project_id.equipment_count, 1) - self.assertEqual(self.project_demo1.equipment_count, 2) - self.assertEqual(self.equipment_demo3.project_id.equipment_count, 1) + self.assertEqual(self.project_demo.equipment_count, 2) + self.assertEqual(self.equipment_demo.project_id.equipment_count, 1) - def test_request_onchange_equipment(self): - req1 = self.env["maintenance.request"].new({"name": "My test request #1"}) - self.assertFalse(req1.project_id) - req1.equipment_id = self.equipment1 - req1.onchange_equipment_id() - self.assertEqual(req1.project_id, self.equipment1.project_id) - - req2 = self.env["maintenance.request"].new({"name": "My test request #2"}) - req2.equipment_id = self.equipment2 - req2.onchange_equipment_id() - self.assertFalse(req2.project_id) + @users("test-user") + def test_request_equipment(self): + request_form_1 = Form(self.env["maintenance.request"]) + request_form_1.name = "My test request #1" + self.assertFalse(request_form_1.project_id) + request_form_1.equipment_id = self.equipment1 + self.assertEqual(request_form_1.project_id, self.equipment1.project_id) + request_form_2 = Form(self.env["maintenance.request"]) + request_form_2.name = "My test request #2" + request_form_2.equipment_id = self.equipment2 + self.assertFalse(request_form_2.project_id) def test_generate_requests(self): self.cron.method_direct_trigger() - generated_requests = self.env["maintenance.request"].search( [("project_id", "!=", False)] ) @@ -79,12 +104,11 @@ def test_generate_requests(self): self.assertEqual(req.task_id, req.equipment_id.preventive_default_task_id) self.assertEqual(req.project_id.maintenance_request_count, 1) - def test_action_views(self): + def test_project_action_views(self): act1 = self.project1.action_view_equipment_ids() self.assertEqual(act1["domain"][0][2], self.project1.id) self.assertEqual(act1["context"]["default_project_id"], self.project1.id) self.assertFalse(act1["context"]["default_create_project_from_equipment"]) - act2 = self.project1.action_view_maintenance_request_ids() self.assertEqual(act2["domain"][0][2], self.project1.id) self.assertEqual(act2["context"]["default_project_id"], self.project1.id) diff --git a/maintenance_project/views/maintenance_equipment_views.xml b/maintenance_project/views/maintenance_equipment_views.xml index 554be3b94..3707413f0 100644 --- a/maintenance_project/views/maintenance_equipment_views.xml +++ b/maintenance_project/views/maintenance_equipment_views.xml @@ -5,7 +5,7 @@ - + @@ -14,7 +14,7 @@ - + @@ -23,10 +23,13 @@ - + -
+
Project:
@@ -37,14 +40,24 @@ - - + + @@ -52,6 +65,7 @@ name="preventive_default_task_id" domain="[('project_id', '=', project_id)]" context="{'default_project_id': project_id}" + groups="project.group_project_user" /> diff --git a/maintenance_project/views/maintenance_request_views.xml b/maintenance_project/views/maintenance_request_views.xml index dadd5c9f6..a3f489bf1 100644 --- a/maintenance_project/views/maintenance_request_views.xml +++ b/maintenance_project/views/maintenance_request_views.xml @@ -5,7 +5,7 @@ - + @@ -14,7 +14,7 @@ - + @@ -23,10 +23,13 @@ - + -
+
Project:
@@ -37,11 +40,14 @@ - + + + diff --git a/maintenance_project/views/project_project_views.xml b/maintenance_project/views/project_project_views.xml index e960b9115..75764358c 100644 --- a/maintenance_project/views/project_project_views.xml +++ b/maintenance_project/views/project_project_views.xml @@ -5,14 +5,21 @@ - - + +
@@ -25,6 +32,7 @@ class="o_project_kanban_box" name="action_view_maintenance_request_ids" type="object" + groups="maintenance.group_equipment_manager" >
@@ -46,6 +54,7 @@ name="action_view_equipment_ids" type="object" icon="fa-ticket" + groups="maintenance.group_equipment_manager" >