From e4eb57e349a8d4a38feed1c210e481d9e751ea6f Mon Sep 17 00:00:00 2001 From: Marc Durepos Date: Fri, 25 Oct 2024 10:35:21 -0400 Subject: [PATCH] fsm_equipment, bemade_fsm: Multiple UX improvements + migration script - Task list view (bemade_fsm) cleaned up - Add equipment to service to task list view (bemade_fsm) - Give base.group_user access to read client application details - Add migration script for fsm_equipment to refactor components into a hierarchy of equipment. - Add the notion of equipment hierarchy instead of components. partner_id field is only to be filled on the root equipment, to facilitate viewing client equipment lists without the clutter of all the subcomponents. - Add the notion of "inherited partner id" to show the root's partner_id on child equipment (components) form view. - Improve the interventions list on the equipment form view. Added a custom embedded tree view with limited fields, ordered by date. - Make the default search for equipment only search for root equipments (parent_id = False) --- bemade_fsm/views/task_views.xml | 8 ++++- customer_applications/security/groups.xml | 10 +++--- fsm_equipment/__manifest__.py | 1 + .../migrations/17.0.0.2.0/post-migrate.py | 2 +- fsm_equipment/models/equipment.py | 32 ++++++++++++++++- fsm_equipment/models/res_partner.py | 2 +- fsm_equipment/views/equipment_views.xml | 35 ++++++++++++++++--- fsm_equipment/views/project_task_views.xml | 14 ++++++++ 8 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 fsm_equipment/views/project_task_views.xml diff --git a/bemade_fsm/views/task_views.xml b/bemade_fsm/views/task_views.xml index 6bce7cd..bd0d0e7 100644 --- a/bemade_fsm/views/task_views.xml +++ b/bemade_fsm/views/task_views.xml @@ -80,7 +80,7 @@ project_list - + @@ -92,6 +92,12 @@ hide + + hide + + + hide + diff --git a/customer_applications/security/groups.xml b/customer_applications/security/groups.xml index f20d6f0..23e3fbc 100644 --- a/customer_applications/security/groups.xml +++ b/customer_applications/security/groups.xml @@ -1,12 +1,14 @@ - - Applications Admin - - Applications User + + Applications Admin + + + + \ No newline at end of file diff --git a/fsm_equipment/__manifest__.py b/fsm_equipment/__manifest__.py index 25d8e21..2ea15b1 100644 --- a/fsm_equipment/__manifest__.py +++ b/fsm_equipment/__manifest__.py @@ -30,6 +30,7 @@ "security/ir.model.access.csv", "views/equipment_views.xml", "views/res_partner_views.xml", + "views/project_task_views.xml", ], "assets": {}, "installable": True, diff --git a/fsm_equipment/migrations/17.0.0.2.0/post-migrate.py b/fsm_equipment/migrations/17.0.0.2.0/post-migrate.py index 86df8fb..b62c2d1 100644 --- a/fsm_equipment/migrations/17.0.0.2.0/post-migrate.py +++ b/fsm_equipment/migrations/17.0.0.2.0/post-migrate.py @@ -3,7 +3,7 @@ from odoo.tools.sql import SQL def migrate(cr, version): - sql = "select * from equipment_component" + sql = "select * from fsm_equipment_component" cr.execute(SQL(sql)) components = cr.dictfetchall() sql = "select * from fsm_equipment_component_purpose" diff --git a/fsm_equipment/models/equipment.py b/fsm_equipment/models/equipment.py index dbc75d6..18cd5c9 100644 --- a/fsm_equipment/models/equipment.py +++ b/fsm_equipment/models/equipment.py @@ -1,5 +1,6 @@ from odoo import models, fields, api, _ from odoo.osv import expression +from odoo.exceptions import ValidationError class Equipment(models.Model): @@ -28,7 +29,7 @@ class Equipment(models.Model): string="Physical Address", tracking=True, ondelete="restrict", - required=True, + required=False, ) location_notes = fields.Text( @@ -55,6 +56,13 @@ class Equipment(models.Model): "fsm.equipment", tracking=True, ) + inherited_partner_id = fields.Many2one( + comodel_name="res.partner", + string="Main Equipment Location", + readonly=True, + compute="_compute_inherited_partner_id", + recursive=True, + ) child_ids = fields.One2many( "fsm.equipment", @@ -69,6 +77,28 @@ class Equipment(models.Model): help="The product that represents this equipment, if any.", ) + @api.depends("parent_id", "parent_id.partner_id") + def _compute_inherited_partner_id(self): + for rec in self: + if not rec.parent_id: + rec.inherited_partner_id = False + continue + rec.inherited_partner_id = ( + rec.parent_id.partner_id or rec.parent_id.inherited_partner_id + ) + + @api.constrains("product_id", "partner_id") + def _constrain_only_root_has_partner(self): + for rec in self: + if rec.partner_id and rec.parent_id: + raise ValidationError( + _("Only top-level (root) equipments can be linked to a partner.") + ) + if not rec.parent_id and not rec.partner_id: + raise ValidationError( + _("Top-level (root) equipments must be linked to a partner.") + ) + @api.model def name_search(self, name="", args=None, operator="ilike", limit=100): diff --git a/fsm_equipment/models/res_partner.py b/fsm_equipment/models/res_partner.py index cd16a33..8cc0f30 100644 --- a/fsm_equipment/models/res_partner.py +++ b/fsm_equipment/models/res_partner.py @@ -41,7 +41,7 @@ class Partner(models.Model): def _compute_equipment_count(self): for rec in self: all_equipment_ids = self.env["fsm.equipment"].search( - [("partner_id", "=", rec.id)] + [("partner_id", "=", rec.id), ("parent_id", "=", False)] ) rec.equipment_count = len(all_equipment_ids) diff --git a/fsm_equipment/views/equipment_views.xml b/fsm_equipment/views/equipment_views.xml index f2997e8..c3528be 100644 --- a/fsm_equipment/views/equipment_views.xml +++ b/fsm_equipment/views/equipment_views.xml @@ -11,6 +11,7 @@ + @@ -22,6 +23,17 @@ 'show_address': 1 }" options='{"always_reload": True}' + invisible="parent_id" + required="not parent_id" + /> + - + + - - + + + + + + + + + + @@ -102,6 +123,9 @@ Equipment fsm.equipment tree,form + + {'search_default_parent_only': True} + @@ -109,12 +133,14 @@ fsm.equipment + - + fsm.equipment.tag tree,form + + + + project.task.view.tree.equipment + project.task + + + + + + + + \ No newline at end of file