From ad59ebeaceca395f642edf82b9d8f84890b1880b Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 26 Jan 2021 16:58:04 +0000 Subject: [PATCH] [FIX] hr_holidays: Impossible to delete a refused Time-Off request Steps to reproduce the bug: -Create a time-Off request R1 for 27/01 -Refuse R1 -Create another Time-Off request R2 for the same date 27/01 -Set R1 in draft -Try to delete R1 Bug: A ValidationError was raised: You can not set 2 time off that overlaps on the same day for the same employee. opw:2447540 closes odoo/odoo#68005 X-original-commit: 22db3d4168b61f2904e331ac570a1df4904d9791 Signed-off-by: Simon Goffin (sig) --- addons/hr_holidays/models/hr_leave.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index 8ac4c140b38..872ed88c839 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -558,6 +558,8 @@ class HolidaysRequest(models.Model): @api.constrains('date_from', 'date_to', 'employee_id') def _check_date(self): + if self.env.context.get('leave_skip_date_check', False): + return for holiday in self.filtered('employee_id'): domain = [ ('date_from', '<', holiday.date_to), @@ -831,6 +833,9 @@ class HolidaysRequest(models.Model): for holiday in self.filtered(lambda holiday: holiday.state not in ['draft', 'cancel', 'confirm']): raise UserError(error_message % (state_description_values.get(holiday.state),)) + def unlink(self): + return super(HolidaysRequest, self.with_context(leave_skip_date_check=True)).unlink() + def copy_data(self, default=None): if default and 'date_from' in default and 'date_to' in default: default['request_date_from'] = default.get('date_from')