From 5af4b36e2b44fc6f3ee15419b9c1a0a597a614e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9rome=20Maes?= Date: Mon, 19 Jun 2017 11:20:00 +0200 Subject: [PATCH] [FIX] project_timesheet_holidays: refusing leaves delete timesheet When refusing leave, we can not remove linked timesheet, since they are attached to the leave. We need to first detach it, then remove the timesheet entries. Also, add a test about the removal of linked timesheets. --- addons/project_timesheet_holidays/models/hr_holidays.py | 1 + .../tests/test_timesheet_holidays.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/addons/project_timesheet_holidays/models/hr_holidays.py b/addons/project_timesheet_holidays/models/hr_holidays.py index 2717a4eab59..a2d2457f573 100644 --- a/addons/project_timesheet_holidays/models/hr_holidays.py +++ b/addons/project_timesheet_holidays/models/hr_holidays.py @@ -61,5 +61,6 @@ class Holidays(models.Model): def action_refuse(self): """ Remove the timesheets linked to the refused holidays """ result = super(Holidays, self).action_refuse() + self.mapped('timesheet_ids').write({'holiday_id': False}) self.mapped('timesheet_ids').unlink() return result diff --git a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py index f49cf00ed14..f98817fdeec 100644 --- a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py +++ b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py @@ -72,6 +72,10 @@ class TestTimesheetHolidays(TestTimesheet): holiday.sudo().action_validate() self.assertEquals(len(holiday.timesheet_ids), number_of_days, 'Number of generated timesheets should be the same as the leave duration (1 per day)') + # manager refuse the leave + holiday.sudo().action_refuse() + self.assertEquals(len(holiday.timesheet_ids), 0, 'Number of linked timesheets should be zero, since the leave is refused.') + def test_validate_without_timesheet(self): # employee creates a leave request number_of_days = (self.leave_end_datetime - self.leave_start_datetime).days