diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 96eb1a830a7..4f691077cb6 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -147,6 +147,11 @@ class HolidaysAllocation(models.Model): ('duration_check', "CHECK( ( number_of_days > 0 AND allocation_type='regular') or (allocation_type != 'regular'))", "The duration must be greater than 0."), ] + @api.constrains('date_from', 'date_to') + def _check_date_from_date_to(self): + if any(allocation.date_to and allocation.date_from > allocation.date_to for allocation in self): + raise UserError(_("The Start Date of the Validity Period must be anterior to the End Date.")) + # The compute does not get triggered without a depends on record creation # aka keep the 'useless' depends @api.depends_context('uid')