Update re_unit.py

This commit is contained in:
zainab2097 2024-08-08 15:01:18 +03:00 committed by GitHub
parent 3dd4c57c7d
commit b6d9961bf2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 0 deletions

View File

@ -72,7 +72,25 @@ class Unit(models.Model):
_sql_constraints = [
('name', 'unique(name)', _('Name must be unique.')),
]
# Smart button to count related maintenance records
maintenance_count = fields.Integer(string="Maintenance Count", compute='_compute_maintenance_count')
def _compute_maintenance_count(self):
for record in self:
record.maintenance_count = self.env['property.management.maintenance'].search_count([
('unit_ids', 'in', record.id)
])
def action_view_maintenance(self):
return {
'type': 'ir.actions.act_window',
'name': 'Maintenance',
'view_mode': 'tree,form',
'res_model': 'property.management.maintenance',
'domain': [('unit_ids', 'in', self.id)],
'context': dict(self.env.context),
}
@api.depends('state')
def set_color(self):
for record in self: