2024-08-20 15:58:17 -04:00
|
|
|
from odoo import models, fields, api, _
|
2023-06-14 15:51:20 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class Equipment(models.Model):
|
2024-08-20 15:58:17 -04:00
|
|
|
_name = "fsm.equipment"
|
|
|
|
|
_description = "Partner-Owned Equipment"
|
2024-06-11 21:26:26 -04:00
|
|
|
_inherit = ["mail.thread", "mail.activity.mixin"]
|
2023-06-14 15:51:20 -04:00
|
|
|
|
2024-08-20 15:58:17 -04:00
|
|
|
code = fields.Char(
|
|
|
|
|
tracking=True,
|
|
|
|
|
)
|
|
|
|
|
name = fields.Char(
|
|
|
|
|
tracking=True,
|
|
|
|
|
required=True,
|
2024-06-11 21:26:26 -04:00
|
|
|
)
|
2023-06-14 15:51:20 -04:00
|
|
|
|
2023-11-15 18:49:18 -05:00
|
|
|
tag_ids = fields.Many2many(
|
2024-08-20 15:58:17 -04:00
|
|
|
comodel_name="fsm.equipment.tag",
|
|
|
|
|
string="Tags",
|
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
|
|
|
|
2024-08-20 15:58:17 -04:00
|
|
|
partner_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
|
|
|
)
|
|
|
|
|
|
2024-08-20 15:58:17 -04:00
|
|
|
location_notes = fields.Text(
|
|
|
|
|
string="Physical Location Notes",
|
|
|
|
|
tracking=True,
|
|
|
|
|
help="Any useful information about physical location "
|
|
|
|
|
"(door codes, directions, etc.).",
|
|
|
|
|
)
|
2023-11-15 18:49:18 -05:00
|
|
|
|
|
|
|
|
task_ids = fields.Many2many(
|
2024-06-11 21:26:26 -04:00
|
|
|
comodel_name="project.task",
|
2024-08-21 13:52:35 -04:00
|
|
|
relation="fsm_task_equipment_rel",
|
2023-11-15 18:49:18 -05:00
|
|
|
column1="equipment_id",
|
|
|
|
|
column2="task_id",
|
2024-06-11 21:26:26 -04:00
|
|
|
string="Interventions",
|
2023-11-15 18:49:18 -05:00
|
|
|
)
|
2023-06-14 15:51:20 -04:00
|
|
|
|
2024-08-22 15:10:47 -04:00
|
|
|
active = fields.Boolean(
|
|
|
|
|
default=True,
|
|
|
|
|
tracking=True,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
equipment_component_ids = fields.One2many(
|
|
|
|
|
"fsm.equipment.component",
|
|
|
|
|
inverse_name="equipment_id",
|
|
|
|
|
tracking=True,
|
|
|
|
|
)
|
2024-06-03 10:11:19 -04:00
|
|
|
|
2023-06-14 15:51:20 -04:00
|
|
|
@api.model
|
2024-06-11 21:26:26 -04:00
|
|
|
def name_search(self, name="", args=None, operator="ilike", limit=100):
|
2023-06-14 15:51:20 -04:00
|
|
|
args = args or []
|
|
|
|
|
if name:
|
2024-06-11 21:26:26 -04:00
|
|
|
equipments = self.search(
|
|
|
|
|
[
|
|
|
|
|
"|",
|
|
|
|
|
"|",
|
2024-08-20 15:58:17 -04:00
|
|
|
("code", operator, name),
|
2024-06-11 21:26:26 -04:00
|
|
|
("name", operator, name),
|
2024-08-20 15:58:17 -04:00
|
|
|
("partner_id.name", operator, name),
|
2024-06-11 21:26:26 -04:00
|
|
|
],
|
|
|
|
|
limit=limit,
|
|
|
|
|
)
|
2023-06-14 15:51:20 -04:00
|
|
|
else:
|
|
|
|
|
equipments = self.search(args, limit=limit)
|
2024-05-02 09:56:52 -04:00
|
|
|
return [(equipment.id, equipment.display_name) for equipment in equipments]
|
2023-06-15 13:16:37 -04:00
|
|
|
|
|
|
|
|
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,
|
2024-08-20 15:58:17 -04:00
|
|
|
"res_model": "fsm.equipment",
|
2024-06-11 21:26:26 -04:00
|
|
|
"type": "ir.actions.act_window",
|
2023-06-26 11:41:07 -04:00
|
|
|
}
|
2023-07-26 15:38:46 -04:00
|
|
|
|
2024-08-20 15:58:17 -04:00
|
|
|
@api.depends("code", "name")
|
2024-09-06 08:27:31 -04:00
|
|
|
def _compute_display_name(self):
|
2023-07-26 15:38:46 -04:00
|
|
|
for rec in self:
|
2024-08-20 15:58:17 -04:00
|
|
|
tag_part = "[%s] " % rec.code if rec.code else ""
|
2024-01-17 14:59:03 -05:00
|
|
|
name = rec.name or ""
|
2024-09-06 08:27:31 -04:00
|
|
|
rec.display_name = tag_part + name
|