From c89c0e70da1e09c43eee8e76c7094dcc114c451b Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 23 Jan 2019 14:22:02 +0000 Subject: [PATCH] [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 --- addons/hr_holidays/models/hr_leave.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index b4f045bdc1b..fce0b699407 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -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):