[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) <sig@openerp.com>
This commit is contained in:
Goffin Simon
2021-03-17 11:29:14 +00:00
parent f86f92d462
commit ad59ebeace
+5
View File
@@ -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')