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')