[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.
This commit is contained in:
Jérome Maes
2017-06-20 09:00:32 +02:00
parent d36f8d478a
commit 5af4b36e2b
2 changed files with 5 additions and 0 deletions
@@ -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
@@ -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