From 55e4f947526ef49a287c3ba44318e06f5cc4fa00 Mon Sep 17 00:00:00 2001 From: Kevin Baptiste Date: Mon, 14 Feb 2022 13:41:10 +0000 Subject: [PATCH] [FIX] hr_holidays: correctly show employee's Dashboard Only show the leaves taken by the current employee when using the Leaves stat button on an employee's form. closes odoo/odoo#84609 Taskid: 2764912 X-original-commit: 7413e7c5834713381870073db02019c7dd8ea6c4 Signed-off-by: Kevin Baptiste --- addons/hr_holidays/models/hr_employee.py | 6 +----- addons/hr_holidays/models/hr_leave.py | 10 ++++++---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/addons/hr_holidays/models/hr_employee.py b/addons/hr_holidays/models/hr_employee.py index 2c5ed40de6f..330e31c54c5 100644 --- a/addons/hr_holidays/models/hr_employee.py +++ b/addons/hr_holidays/models/hr_employee.py @@ -252,16 +252,12 @@ class HrEmployee(models.Model): return super()._get_user_m2o_to_empty_on_archived_employees() + ['leave_manager_id'] def action_time_off_dashboard(self): - domain = [] - if self.env.context.get('active_ids'): - domain = [('employee_id', 'in', self.env.context.get('active_ids', []))] - return { 'name': _('Time Off Dashboard'), 'type': 'ir.actions.act_window', 'res_model': 'hr.leave', 'views': [[self.env.ref('hr_holidays.hr_leave_employee_view_dashboard').id, 'calendar']], - 'domain': domain, + 'domain': [('employee_id', 'in', self.ids)], 'context': { 'employee_id': self.ids, }, diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index e4a2df6c7cc..ff945f33fdf 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -201,8 +201,8 @@ class HolidaysRequest(models.Model): # To display in form view supported_attachment_ids = fields.Many2many( 'ir.attachment', string="Attach File", compute='_compute_supported_attachment_ids', - inverse='_inverse_supported_attachment_ids', compute_sudo=True) - supported_attachment_ids_count = fields.Integer(compute='_compute_supported_attachment_ids', compute_sudo=True) + inverse='_inverse_supported_attachment_ids') + supported_attachment_ids_count = fields.Integer(compute='_compute_supported_attachment_ids') # UX fields all_employee_ids = fields.Many2many('hr.employee', compute='_compute_all_employees') leave_type_request_unit = fields.Selection(related='holiday_status_id.request_unit', readonly=True) @@ -641,7 +641,9 @@ class HolidaysRequest(models.Model): def _inverse_supported_attachment_ids(self): for holiday in self: - holiday.sudo().attachment_ids = holiday.supported_attachment_ids + holiday.supported_attachment_ids.write({ + 'res_id': holiday.id, + }) @api.constrains('date_from', 'date_to', 'employee_id') def _check_date(self): @@ -958,7 +960,7 @@ class HolidaysRequest(models.Model): raise UserError(_("You can't manually archive a time off.")) is_officer = self.env.user.has_group('hr_holidays.group_hr_holidays_user') or self.env.is_superuser() - if not is_officer: + if not is_officer and values.keys() - {'supported_attachment_ids', 'message_main_attachment_id'}: if any(hol.date_from.date() < fields.Date.today() and hol.employee_id.leave_manager_id != self.env.user for hol in self): raise UserError(_('You must have manager rights to modify/validate a time off that already begun'))