I have a problem with the time off module I want to create a new time off request for the employee automatically via code but it seems imposible, I tried with this code but I get validation error, the code is:
attendance_list =[]
for employee in all_employees:
if employee.name not in attendance_employee_list:
vals = {
'holiday_status_id': 3,
'state': 'confirm',
'user_id': employee.user_id.id,
'number_of_days': 1,
'request_date_from': today,
'request_date_to': today,
'holiday_type': 'employee',
}
self.env['hr.leave'].create(vals)
record = super(self.env['hr.leave'].create(vals))
attendance_list.append(record)
return attendance_list
and the error is:
Validation error
×
The operation cannot be completed: another model needs the record you want to delete. If possible, archive it.
Model: Time Off (hr.leave), Constraint: hr_leave_employee_id_fkey