Update re_unit

This commit is contained in:
zainab2097 2024-08-28 11:57:55 +03:00 committed by GitHub
parent abda0a2f11
commit a5e8266d92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,8 @@ class Unit(models.Model):
_inherit = ['mail.thread', 'mail.activity.mixin'] _inherit = ['mail.thread', 'mail.activity.mixin']
_order = "id desc" _order = "id desc"
attach_nbr = fields.Integer(compute='get_attachments')
active = fields.Boolean(default=True) active = fields.Boolean(default=True)
unlock = fields.Boolean(default=True, string="Unlock") unlock = fields.Boolean(default=True, string="Unlock")
name = fields.Char(string="Unit Name") name = fields.Char(string="Unit Name")
@ -74,6 +76,16 @@ class Unit(models.Model):
] ]
# Smart button to count related maintenance records # Smart button to count related maintenance records
maintenance_count = fields.Integer(string="Maintenance Count", compute='_compute_maintenance_count') maintenance_count = fields.Integer(string="Maintenance Count", compute='_compute_maintenance_count')
def get_attachments(self):
action = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
action['domain'] = str([('res_model', '=', 're.unit'),('res_id', 'in', self.ids)])
action['context'] = "{'default_res_model': '%s','default_res_id': %d}" % (self._name, self.id)
return action
def get_attachments(self):
res = super(Unit, self).get_attachments()
domain = [('res_model', '=', 're.unit'), ('res_id', '=', self.id)]
self.attach_nbr = self.env['ir.attachment'].search_count(domain)
return res
def _compute_maintenance_count(self): def _compute_maintenance_count(self):
for record in self: for record in self: