[FIX] hr_holidays: fix access error for officer

Time Off officer would sometimes get an AccessError when requesting
leaves for many employees.

opw-3220920

closes odoo/odoo#115886

X-original-commit: f38a3d1ee398242f5dad6860bac95143256015b5
Signed-off-by: Kevin Baptiste <kba@odoo.com>
This commit is contained in:
Kevin Baptiste
2023-03-20 18:13:17 +01:00
parent 0467440dbc
commit 2707556f5e
+6 -6
View File
@@ -203,7 +203,7 @@ class HolidaysRequest(models.Model):
states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]},
help='By Employee: Allocation/Request for individual Employee, By Employee Tag: Allocation/Request for group of employees in category')
employee_ids = fields.Many2many(
'hr.employee', compute='_compute_from_holiday_type', store=True, string='Employees', readonly=False,
'hr.employee', compute='_compute_from_holiday_type', store=True, string='Employees', readonly=False, groups="hr_holidays.group_hr_holidays_user",
states={'cancel': [('readonly', True)], 'refuse': [('readonly', True)], 'validate1': [('readonly', True)], 'validate': [('readonly', True)]})
multi_employee = fields.Boolean(
compute='_compute_from_employee_ids', store=True, compute_sudo=False,
@@ -703,9 +703,9 @@ class HolidaysRequest(models.Model):
def _check_holidays(self):
for holiday in self:
mapped_days_date = holiday.date_from.date() or None
mapped_days = self.holiday_status_id.get_employees_days((holiday.employee_id | holiday.employee_ids).ids, mapped_days_date)
mapped_days = self.holiday_status_id.get_employees_days((holiday.employee_id | holiday.sudo().employee_ids).ids, mapped_days_date)
if holiday.holiday_type != 'employee'\
or not holiday.employee_id and not holiday.employee_ids\
or not holiday.employee_id and not holiday.sudo().employee_ids\
or holiday.holiday_status_id.requires_allocation == 'no':
continue
if holiday.employee_id:
@@ -716,7 +716,7 @@ class HolidaysRequest(models.Model):
'Please also check the time off waiting for validation.'))
else:
unallocated_employees = []
for employee in holiday.employee_ids:
for employee in holiday.sudo().employee_ids:
leave_days = mapped_days[employee.id][holiday.holiday_status_id.id]
if float_compare(leave_days['remaining_leaves'], self.number_of_days, precision_digits=2) == -1\
or float_compare(leave_days['virtual_remaining_leaves'], self.number_of_days, precision_digits=2) == -1:
@@ -1048,7 +1048,7 @@ class HolidaysRequest(models.Model):
raise UserError(error_message % state_description_values.get(self[:1].state))
if hol.date_from < now:
raise UserError(_('You cannot delete a time off which is in the past'))
if hol.employee_ids and not hol.employee_id:
if hol.sudo().employee_ids and not hol.employee_id:
raise UserError(_('You cannot delete a time off assigned to several employees'))
else:
for holiday in self.filtered(lambda holiday: holiday.state not in ['draft', 'cancel', 'confirm']):
@@ -1501,7 +1501,7 @@ class HolidaysRequest(models.Model):
if not is_officer and self.env.user != holiday.employee_id.leave_manager_id:
raise UserError(_('You must be either %s\'s manager or Time off Manager to approve this leave') % (holiday.employee_id.name))
if (state == 'validate' and val_type == 'manager') and self.env.user != (holiday.employee_id | holiday.employee_ids).leave_manager_id:
if (state == 'validate' and val_type == 'manager') and self.env.user != (holiday.employee_id | holiday.sudo().employee_ids).leave_manager_id:
if holiday.employee_id:
employees = holiday.employee_id
else: