I want add a rule create time off for employees.
But when I check base 'hr_holidays', must to have allow this employee is Time off/ Officer: Manage all requests or this employee is leave manager.
def write(self, values):
if 'active' in values and not self.env.context.get('from_cancel_wizard'):
raise UserError(_("You can't manually archive/unarchive 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 and values.keys() - {'attachment_ids', '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'))
# Unlink existing resource.calendar.leaves for validated time off
if 'state' in values and values['state'] != 'validate':
validated_leaves = self.filtered(lambda l: l.state == 'validate')
validated_leaves._remove_resource_leave()
employee_id = values.get('employee_id', False)
if not self.env.context.get('leave_fast_create'):
if values.get('state'):
self._check_approval_update(values['state'])
if any(holiday.validation_type == 'both' for holiday in self):
if values.get('employee_id'):
employees = self.env['hr.employee'].browse(values.get('employee_id'))
else:
employees = self.mapped('employee_id')
self._check_double_validation_rules(employees, values['state'])
if 'date_from' in values:
values['request_date_from'] = values['date_from']
if 'date_to' in values:
values['request_date_to'] = values['date_to']
result = super(HolidaysRequest, self).write(values)
if not self.env.context.get('leave_fast_create'):
for holiday in self:
if employee_id:
holiday.add_follower(employee_id)
return result
I want to allow create time off in the past for all employees (User internal).
Please help me!