[IMP] hr_holidays: Avoid 2 leaves on the same day when changing state

Purpose
=======

There is already a check triggered when we modify the start/end date.

But it's still possible to:
- Create a leave A
- Refuse it
- Create a leave B on the same day
- Reset the leave A in draft state

Specification
=============

The test should also be done when modifying the employee or the state.

closes odoo/odoo#30480
This commit is contained in:
Yannick Tivisse
2019-01-24 11:22:46 +00:00
parent 4ba8f51d87
commit c89c0e70da
+2 -2
View File
@@ -400,7 +400,7 @@ class HolidaysRequest(models.Model):
else:
holiday.can_approve = True
@api.constrains('date_from', 'date_to')
@api.constrains('date_from', 'date_to', 'state', 'employee_id')
def _check_date(self):
for holiday in self:
domain = [
@@ -412,7 +412,7 @@ class HolidaysRequest(models.Model):
]
nholidays = self.search_count(domain)
if nholidays:
raise ValidationError(_('You can not have 2 time off that overlaps on the same day.'))
raise ValidationError(_('You can not set 2 times off that overlaps on the same day for the same employee.'))
@api.constrains('state', 'number_of_days', 'holiday_status_id')
def _check_holidays(self):