[FIX] hr_holidays: Allow creating time off in the past
Purpose ======= In the case a time off is created: - In the past - Using support documents An invalid user error is raised in the interface, because the webclient is sending values for the field 'supported_attachment_ids' (Example: [(6, 0, [])]) which is writing by inverse relationship on the field 'attachment_ids'. On the other hand, it should be possible for an employee to add attachment on the time off after it has begun. closes odoo/odoo#103626 Taskid: 3032232 X-original-commit: c32c22ec267626322aebb7af4ee36b573c71760d Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
This commit is contained in:
@@ -957,7 +957,7 @@ class HolidaysRequest(models.Model):
|
||||
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() - {'supported_attachment_ids', 'message_main_attachment_id'}:
|
||||
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'))
|
||||
|
||||
|
||||
@@ -58,6 +58,12 @@ class TestLeaveRequests(TestHrHolidaysCommon):
|
||||
'employee_requests': 'yes',
|
||||
'leave_validation_type': 'both',
|
||||
})
|
||||
cls.holidays_support_document = LeaveType.create({
|
||||
'name': 'Time off with support document',
|
||||
'support_document': True,
|
||||
'requires_allocation': 'no',
|
||||
'leave_validation_type': 'no_validation',
|
||||
})
|
||||
|
||||
cls.set_employee_create_date(cls.employee_emp_id, '2010-02-03 00:00:00')
|
||||
cls.set_employee_create_date(cls.employee_hruser_id, '2010-02-03 00:00:00')
|
||||
@@ -975,3 +981,15 @@ class TestLeaveRequests(TestHrHolidaysCommon):
|
||||
# The meeting is archived when the leave is cancelled
|
||||
leave.with_user(self.user_employee_id)._action_user_cancel('Cancel leave')
|
||||
self.assertFalse(leave.meeting_id.active)
|
||||
|
||||
def test_create_support_document_in_the_past(self):
|
||||
with freeze_time('2022-10-19'):
|
||||
self.env['hr.leave'].with_user(self.user_employee_id).create({
|
||||
'name': 'Holiday Request',
|
||||
'employee_id': self.employee_emp_id,
|
||||
'holiday_status_id': self.holidays_support_document.id,
|
||||
'date_from': '2022-10-17',
|
||||
'date_to': '2022-10-17',
|
||||
'number_of_days': 1,
|
||||
'supported_attachment_ids': [(6, 0, [])], # Sent by webclient
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user