From 55107871e334e9c8c6927a5e7cda680dbcd07126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Fri, 13 Sep 2024 09:08:54 +0200 Subject: [PATCH 1/4] [IMP] maintenance_project: Remove the Project > Administrator permission dependency TT50829 --- maintenance_project/__manifest__.py | 3 +- .../demo/demo_maintenance_project.xml | 8 +- .../migrations/17.0.2.0.0/post-migration.py | 11 +++ .../models/maintenance_equipment.py | 24 +++--- .../security/maintenance_project_security.xml | 6 -- .../static/description/index.html | 11 +-- .../tests/test_maintenance_project.py | 85 ++++++++++++------- .../views/maintenance_equipment_views.xml | 23 +++-- .../models/maintenance_equipment.py | 4 +- .../tests/test_maintenance_timesheet.py | 7 +- 10 files changed, 108 insertions(+), 74 deletions(-) create mode 100644 maintenance_project/migrations/17.0.2.0.0/post-migration.py delete mode 100644 maintenance_project/security/maintenance_project_security.xml diff --git a/maintenance_project/__manifest__.py b/maintenance_project/__manifest__.py index 93e37c578..496834f50 100644 --- a/maintenance_project/__manifest__.py +++ b/maintenance_project/__manifest__.py @@ -3,14 +3,13 @@ { "name": "Maintenance Projects", "summary": "Adds projects to maintenance equipments and requests", - "version": "17.0.1.0.0", + "version": "17.0.2.0.0", "author": "Odoo Community Association (OCA), Solvos", "license": "AGPL-3", "category": "Maintenance", "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/demo/demo_maintenance_project.xml b/maintenance_project/demo/demo_maintenance_project.xml index df3893b7c..6f61370f4 100644 --- a/maintenance_project/demo/demo_maintenance_project.xml +++ b/maintenance_project/demo/demo_maintenance_project.xml @@ -21,7 +21,6 @@ S/N 1 MODEL1 - @@ -36,7 +35,6 @@ S/N 2 MODEL2 - S/N 3 MODEL3 - + diff --git a/maintenance_project/migrations/17.0.2.0.0/post-migration.py b/maintenance_project/migrations/17.0.2.0.0/post-migration.py new file mode 100644 index 000000000..84d02601d --- /dev/null +++ b/maintenance_project/migrations/17.0.2.0.0/post-migration.py @@ -0,0 +1,11 @@ +# Copyright 2024 Tecnativa - Víctor Martínez +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + env.ref("maintenance.group_equipment_manager").write( + {"implied_ids": [(3, env.ref("project.group_project_manager").id)]} + ) 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/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 3e35cc5e4..bb9b336bf 100644 --- a/maintenance_project/static/description/index.html +++ b/maintenance_project/static/description/index.html @@ -8,11 +8,10 @@ /* :Author: David Goodger (goodger@python.org) -:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $ +:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $ :Copyright: This stylesheet has been placed in the public domain. Default cascading style sheet for the HTML output of Docutils. -Despite the name, some widely supported CSS2 features are used. See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to customize this style sheet. @@ -275,7 +274,7 @@ margin-left: 2em ; margin-right: 2em } -pre.code .ln { color: gray; } /* line numbers */ +pre.code .ln { color: grey; } /* line numbers */ pre.code, code { background-color: #eeeeee } pre.code .comment, code .comment { color: #5C6576 } pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold } @@ -301,7 +300,7 @@ span.pre { white-space: pre } -span.problematic, pre.problematic { +span.problematic { color: red } span.section-subtitle { @@ -418,9 +417,7 @@

Contributors

Maintainers

This module is maintained by the OCA.

- -Odoo Community Association - +Odoo Community Association

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

diff --git a/maintenance_project/tests/test_maintenance_project.py b/maintenance_project/tests/test_maintenance_project.py index 82ff17de4..9d789a506 100644 --- a/maintenance_project/tests/test_maintenance_project.py +++ b/maintenance_project/tests/test_maintenance_project.py @@ -1,21 +1,30 @@ # 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().setUpClass() - 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" + ) + 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, @@ -24,46 +33,61 @@ 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) - - 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) + self.assertEqual(self.project_demo.equipment_count, 2) + self.assertEqual(self.equipment_demo.project_id.equipment_count, 1) - 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): req_name = "My new recurring test request" @@ -95,12 +119,11 @@ def test_generate_requests(self): my_requests = request_obj.search(domain) self.assertEqual(len(my_requests), 2) - 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 28e14b157..7a9766e5a 100644 --- a/maintenance_project/views/maintenance_equipment_views.xml +++ b/maintenance_project/views/maintenance_equipment_views.xml @@ -37,11 +37,24 @@ - - + + diff --git a/maintenance_timesheet/models/maintenance_equipment.py b/maintenance_timesheet/models/maintenance_equipment.py index a5753ba03..4b63546b6 100644 --- a/maintenance_timesheet/models/maintenance_equipment.py +++ b/maintenance_timesheet/models/maintenance_equipment.py @@ -7,7 +7,7 @@ class MaintenanceEquipment(models.Model): _inherit = "maintenance.equipment" - def _prepare_project_from_equipment_values(self, values): - data = super()._prepare_project_from_equipment_values(values) + def _prepare_project_from_equipment_values(self): + data = super()._prepare_project_from_equipment_values() data["allow_timesheets"] = True return data diff --git a/maintenance_timesheet/tests/test_maintenance_timesheet.py b/maintenance_timesheet/tests/test_maintenance_timesheet.py index 9760606ac..a8a4c6015 100644 --- a/maintenance_timesheet/tests/test_maintenance_timesheet.py +++ b/maintenance_timesheet/tests/test_maintenance_timesheet.py @@ -102,7 +102,6 @@ def test_action_view_timesheet_ids(self): self.assertFalse(act1["context"]["readonly_employee_id"]) def test_prepare_project_from_equipment_values(self): - data = self.env["maintenance.equipment"]._prepare_project_from_equipment_values( - {"name": "my name"} - ) - self.assertTrue(data["allow_timesheets"]) + equipment = self.env["maintenance.equipment"].create({"name": "Test equipment"}) + equipment.action_create_project() + self.assertTrue(equipment.project_id.allow_timesheets) From c5e51101c8279b16f80084729fe365c7a58133cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADctor=20Mart=C3=ADnez?= Date: Mon, 16 Sep 2024 09:42:48 +0200 Subject: [PATCH 2/4] [IMP] maintenance_project: Add groups="project.group_project_user" to project/task fields TT50829 --- .../tests/test_maintenance_project.py | 4 +++- .../views/maintenance_equipment_views.xml | 16 ++++++++++------ .../views/maintenance_request_views.xml | 16 +++++++++++----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/maintenance_project/tests/test_maintenance_project.py b/maintenance_project/tests/test_maintenance_project.py index 9d789a506..204a1da2c 100644 --- a/maintenance_project/tests/test_maintenance_project.py +++ b/maintenance_project/tests/test_maintenance_project.py @@ -15,7 +15,9 @@ def setUpClass(cls): cls.project1 = cls.env["project.project"].create({"name": "My project"}) cls.project_demo = cls.env.ref("maintenance_project.project_project_1") new_test_user( - cls.env, login="test-user", groups="maintenance.group_equipment_manager" + cls.env, + login="test-user", + groups="maintenance.group_equipment_manager,project.group_project_user", ) new_test_user( cls.env, diff --git a/maintenance_project/views/maintenance_equipment_views.xml b/maintenance_project/views/maintenance_equipment_views.xml index 7a9766e5a..b58f717a2 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:
@@ -38,11 +41,11 @@ -