From bfa7a47c860452a8b27a942cd50dc61eba72f5cb Mon Sep 17 00:00:00 2001 From: sofiagvaladze Date: Thu, 1 Dec 2022 08:40:46 +0000 Subject: [PATCH] [IMP] hr_holidays: hinder allocation date_to to precede date_from Purpose: In order to reduce the possibility to make errors, make the end date of the validity period always come after the start date. task - 3069666 closes odoo/odoo#106966 Signed-off-by: Kevin Baptiste --- addons/hr_holidays/models/hr_leave_allocation.py | 5 +++++ 1 file changed, 5 insertions(+) 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')