- 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)
51 lines
1.5 KiB
Python
51 lines
1.5 KiB
Python
from odoo import models, fields, api
|
|
from odoo.osv import expression
|
|
|
|
|
|
class Partner(models.Model):
|
|
_inherit = "res.partner"
|
|
|
|
equipment_count = fields.Integer(compute="_compute_equipment_count")
|
|
|
|
owned_equipment_ids = fields.One2many(
|
|
comodel_name="fsm.equipment",
|
|
compute="_compute_owned_equipment_ids",
|
|
string="Owned Equipments",
|
|
)
|
|
|
|
equipment_ids = fields.One2many(
|
|
comodel_name="fsm.equipment",
|
|
inverse_name="partner_id",
|
|
string="Site Equipment",
|
|
)
|
|
|
|
is_service_site = fields.Boolean(
|
|
compute="_compute_is_service_site",
|
|
help="A partner is a service site if it has one or more equipments.",
|
|
store=True,
|
|
compute_sudo=True,
|
|
)
|
|
|
|
@api.depends(
|
|
"equipment_ids",
|
|
"child_ids",
|
|
"child_ids.company_type",
|
|
"child_ids.equipment_ids",
|
|
)
|
|
def _compute_owned_equipment_ids(self):
|
|
for rec in self:
|
|
ids = rec.equipment_ids | rec.child_ids.mapped("equipment_ids")
|
|
rec.owned_equipment_ids = ids or False
|
|
|
|
@api.depends("equipment_ids")
|
|
def _compute_equipment_count(self):
|
|
for rec in self:
|
|
all_equipment_ids = self.env["fsm.equipment"].search(
|
|
[("partner_id", "=", rec.id), ("parent_id", "=", False)]
|
|
)
|
|
rec.equipment_count = len(all_equipment_ids)
|
|
|
|
@api.depends("equipment_ids")
|
|
def _compute_is_service_site(self):
|
|
for rec in self:
|
|
rec.is_service_site = bool(rec.equipment_ids)
|