bemade-addons/bemade_fsm/models/equipment.py

90 lines
2.7 KiB
Python
Raw Normal View History

from odoo import api, fields, models
class Equipment(models.Model):
2024-06-11 21:26:26 -04:00
_name = "bemade_fsm.equipment"
_rec_name = "complete_name"
_description = "Field service equipment"
_inherit = ["mail.thread", "mail.activity.mixin"]
pid_tag = fields.Char(string="P&ID Tag", tracking=True)
2024-06-11 21:26:26 -04:00
name = fields.Char(tracking=True, required=True)
2024-06-11 21:26:26 -04:00
complete_name = fields.Char(
string="Equipment Name", compute="_compute_complete_name", store=True
)
2023-11-15 18:49:18 -05:00
tag_ids = fields.Many2many(
2024-06-11 21:26:26 -04:00
comodel_name="bemade_fsm.equipment.tag",
string="Application",
help=(
"Classify and analyze your equipment categories like: Boiler, Laboratory,"
" Waste water, Pure water"
),
2023-11-15 18:49:18 -05:00
)
2024-06-11 21:26:26 -04:00
description = fields.Text(tracking=True)
2023-11-15 18:49:18 -05:00
partner_location_id = fields.Many2one(
2024-06-11 21:26:26 -04:00
comodel_name="res.partner",
2023-11-15 18:49:18 -05:00
string="Physical Address",
tracking=True,
2024-06-11 21:26:26 -04:00
ondelete="cascade",
2023-11-15 18:49:18 -05:00
)
location_notes = fields.Text(string="Physical Location Notes", tracking=True)
task_ids = fields.Many2many(
2024-06-11 21:26:26 -04:00
comodel_name="project.task",
2023-11-15 18:49:18 -05:00
relation="bemade_fsm_task_equipment_rel",
column1="equipment_id",
column2="task_id",
2024-06-11 21:26:26 -04:00
string="Interventions",
2023-11-15 18:49:18 -05:00
)
2024-06-03 10:11:19 -04:00
active = fields.Boolean(default=True)
2024-06-11 21:26:26 -04:00
@api.depends("partner_location_id")
def _compute_partner(self):
for rec in self:
2024-06-11 21:26:26 -04:00
rec.partner_id = (
rec.partner_location_id and rec.partner_location_id.root_ancestor
)
@api.model
2024-06-11 21:26:26 -04:00
def name_search(self, name="", args=None, operator="ilike", limit=100):
args = args or []
if name:
2024-06-11 21:26:26 -04:00
equipments = self.search(
[
"|",
"|",
("pid_tag", operator, name),
("name", operator, name),
("partner_location_id.name", operator, name),
],
limit=limit,
)
else:
equipments = self.search(args, limit=limit)
return [(equipment.id, equipment.display_name) for equipment in equipments]
def action_view_equipment(self):
return {
2024-06-11 21:26:26 -04:00
"name": "Equipment",
"view_type": "form",
"view_mode": "form",
"res_id": self.id,
"context": self.env.context,
"res_model": "bemade_fsm.equipment",
"type": "ir.actions.act_window",
}
2024-06-11 21:26:26 -04:00
@api.depends("pid_tag", "name")
def _compute_complete_name(self):
for rec in self:
tag_part = "[%s] " % rec.pid_tag if rec.pid_tag else ""
name = rec.name or ""
rec.complete_name = tag_part + name