Merge pull request #2337 from expsa/Esraa-Ensan-hr-tasks

make attachment at training like hr_expense
This commit is contained in:
Esraa-Exp 2025-02-09 20:30:38 +02:00 committed by GitHub
commit 03a0a78fc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 26 deletions

View File

@ -121,20 +121,18 @@ class HrOfficialMission(models.Model):
#########################################
def _compute_attachment_count(self):
attachment = self.env['ir.attachment']
for rec in self:
rec.attachment_count = attachment.search_count([('res_model', '=', self._name), ('res_id', '=', rec.id)])
rec.attachment_count = sum(rec.employee_ids.mapped('attachment_count'))
def action_get_attachment_view(self):
res = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
res['domain'] = [('res_model', '=', 'hr.official.mission.employee'), ('res_id', 'in', self.employee_ids.ids)]
res['context'] = {
'default_res_model': 'hr.official.mission.employee',
'default_res_model': 'hr.official.mission',
'default_res_id': self.id,
'create': True,
'edit': True,
'create': False,
'edit': False,
}
return res
@ -877,31 +875,22 @@ class HrOfficialMissionEmployee(models.Model):
self.status = "draft"
def _compute_attachment_count(self):
attachment = self.env['ir.attachment']
attachment_data = self.env['ir.attachment'].read_group([('res_model', '=', 'hr.official.mission.employee'), ('res_id', 'in', self.ids)], ['res_id'], ['res_id'])
attachment = dict((data['res_id'], data['res_id_count']) for data in attachment_data)
for rec in self:
rec.attachment_count = attachment.search_count([('res_model', '=', self._name), ('res_id', '=', rec.id)])
rec.attachment_count = attachment.get(rec.id, 0)
def action_get_attachment_view(self):
domain = ['&', ('res_model', '=', self._name), ('res_id', 'in', self.ids)]
res_id = self.ids and self.ids[0] or False
return {
'name': _('Attachments'),
'domain': domain,
'res_model': 'ir.attachment',
'type': 'ir.actions.act_window',
'view_id': False,
'view_mode': 'kanban,tree,form',
'view_type': 'form',
'help': _('''<p class="oe_view_nocontent_create">
self.ensure_one()
res = self.env['ir.actions.act_window']._for_xml_id('base.action_attachment')
res['domain'] = [('res_model', '=', 'hr.official.mission.employee'), ('res_id', 'in', self.ids)]
res['context'] = {'default_res_model': 'hr.official.mission.employee', 'default_res_id': self.id}
return res
Attach
documents of %s .</p>''' % (self._description)),
'limit': 80,
'context': "{'default_res_model': '%s','default_res_id': %d}"
% (self._name, res_id)
}
@api.constrains('date_from', 'date_to', 'hour_from', 'hour_to', 'employee_id')
def check_dates(self):