[FIX] hr_holidays: delete calendar event when time off is deleted

Since https://github.com/odoo/odoo/pull/76722, it is possible to cancel an approved time off.
However, the calendar event created when the leave is validated is not archived when the leave is cancelled.

This commit archives the calendar event when the leave is cancelled.

task-2965754

closes odoo/odoo#100413

X-original-commit: d292891997a378578e072cfb01bba612501aa82a
Signed-off-by: Kevin Baptiste <kba@odoo.com>
Signed-off-by: phwa-odoo <phwa@odoo.com>
This commit is contained in:
Philippe Wauthy
2022-09-18 15:26:46 +02:00
parent 186a05ccf7
commit 8b6f1a195a
2 changed files with 43 additions and 0 deletions
+1
View File
@@ -1351,6 +1351,7 @@ class HolidaysRequest(models.Model):
leave_sudo = self.sudo()
leave_sudo.with_context(from_cancel_wizard=True).active = False
leave_sudo.meeting_id.active = False
leave_sudo._remove_resource_leave()
def action_documents(self):
@@ -52,6 +52,13 @@ class TestLeaveRequests(TestHrHolidaysCommon):
'leave_validation_type': 'manager',
})
cls.holidays_type_4 = LeaveType.create({
'name': 'Limited with 2 approvals',
'requires_allocation': 'yes',
'employee_requests': 'yes',
'leave_validation_type': 'both',
})
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')
@@ -843,3 +850,38 @@ class TestLeaveRequests(TestHrHolidaysCommon):
'virtual_leaves_taken': 6,
}
)
def test_cancel_leave(self):
with freeze_time('2020-09-15'):
allocation = self.env['hr.leave.allocation'].create({
'name': 'Annual Time Off',
'employee_id': self.employee_emp_id,
'holiday_status_id': self.holidays_type_4.id,
'number_of_days': 20,
'state': 'confirm',
'date_from': '2020-01-01',
'date_to': '2020-12-31',
})
allocation.action_validate()
leave = 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_type_4.id,
'date_from': '2020-09-21',
'date_to': '2020-09-23',
'number_of_days': 3,
})
# A meeting is only created once the leave is validated
self.assertFalse(leave.meeting_id)
leave.with_user(self.user_hrmanager_id).action_approve()
self.assertFalse(leave.meeting_id)
# A meeting is created in the user's calendar when a leave is validated
leave.with_user(self.user_hrmanager_id).action_validate()
self.assertTrue(leave.meeting_id.active)
# 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)