diff --git a/odex25_realstate/real_estate/models/internal_property.py b/odex25_realstate/real_estate/models/internal_property.py index 2951c903e..0b266a89a 100644 --- a/odex25_realstate/real_estate/models/internal_property.py +++ b/odex25_realstate/real_estate/models/internal_property.py @@ -18,6 +18,27 @@ class Property(models.Model): _inherit = ['mail.thread', 'mail.activity.mixin'] _order = "id desc" + # 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([ + ('property_id', '=', 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': [('property_id', '=', self.id)], + 'context': dict(self.env.context), + } + + # Inherit the form view and add the button + @api.model def _default_image(self): image_path = get_module_resource('real_estate', 'static/src/img', 'default_logo.png')