Skip to content

Commit

Permalink
[IMP] maintenance_project: Remove the Project > Administrator permiss…
Browse files Browse the repository at this point in the history
…ion dependency

TT50829
  • Loading branch information
victoralmau committed Sep 13, 2024
1 parent dc484ef commit 4f90658
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 40 deletions.
1 change: 0 additions & 1 deletion maintenance_project/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 4 additions & 1 deletion maintenance_project/models/maintenance_equipment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright 2019 Solvos Consultoría Informática (<http://www.solvos.es>)
# 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
Expand All @@ -17,7 +18,9 @@ class MaintenanceEquipment(models.Model):
def create(self, vals_list):
project_obj = self.env["project.project"]
for values in vals_list:
if values.get("create_project_from_equipment"):
if values.get("create_project_from_equipment") and self.env.user.has_group(
"project.group_project_manager"
):
new_project = project_obj.create(
self._prepare_project_from_equipment_values(values)
)
Expand Down
6 changes: 0 additions & 6 deletions maintenance_project/security/maintenance_project_security.xml

This file was deleted.

1 change: 0 additions & 1 deletion maintenance_project/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down
112 changes: 81 additions & 31 deletions maintenance_project/tests/test_maintenance_project.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# Copyright 2019 Solvos Consultor??a Inform??tica (<http://www.solvos.es>)
# 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"
)
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",
Expand All @@ -37,40 +47,81 @@ def setUpClass(cls):
"project_id": cls.project1.id,
}
)
cls.equipment_demo = cls.env.ref("maintenance_project.equipment_3")

def test_maintenance_equipment_project_misc(self):
self.assertEqual(self.equipment_demo.name, self.equipment_demo.project_id.name)

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")
@users("test-user")
def test_maintenance_equipment_project_user(self):
equipment_a = self.env["maintenance.equipment"].create(
{
"name": "Test equipment A",
"create_project_from_equipment": True,
}
)
self.assertFalse(equipment_a.project_id)
equipment_b = self.env["maintenance.equipment"].create(
{
"name": "Test equipment B",
"create_project_from_equipment": False,
}
)
self.assertFalse(equipment_b.project_id)
equipment_c = self.env["maintenance.equipment"].create(
{
"name": "Test equipment C",
"create_project_from_equipment": False,
"project_id": self.project1.id,
}
)
self.assertEqual(equipment_c.project_id, self.project1)

def test_maintenance_equipment_project(self):
self.assertEqual(self.equipment1.name, self.equipment1.project_id.name)
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
@users("test-project_manager-user")
def test_maintenance_equipment_project_admin(self):
equipment_a = self.env["maintenance.equipment"].create(
{
"name": "Test equipment A",
"create_project_from_equipment": True,
}
)
self.assertEqual(equipment_a.name, equipment_a.project_id.name)
equipment_b = self.env["maintenance.equipment"].create(
{
"name": "Test equipment B",
"create_project_from_equipment": False,
}
)
self.assertFalse(equipment_b.project_id)
equipment_c = self.env["maintenance.equipment"].create(
{
"name": "Test equipment C",
"create_project_from_equipment": False,
"project_id": self.project1.id,
}
)
self.assertEqual(equipment_c.project_id, self.project1)

def test_project_equipment_count(self):
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):
self.cron.method_direct_trigger()

generated_requests = self.env["maintenance.request"].search(
[("project_id", "!=", False)]
)
Expand All @@ -79,12 +130,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)
3 changes: 3 additions & 0 deletions maintenance_project/views/maintenance_equipment_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@
<field
name="create_project_from_equipment"
attrs="{'invisible': [('id', '!=', False)]}"
groups="project.group_project_manager"
/>
<field name="project_id" invisible="1" />
<field
name="project_id"
attrs="{'invisible': [('create_project_from_equipment', '=', True), ('id', '=', False)]}"
groups="project.group_project_manager"
/>
</xpath>
<xpath expr="//group[@name='maintenance']" position="after">
Expand Down

0 comments on commit 4f90658

Please sign in to comment.