[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 <kba@odoo.com>
This commit is contained in:
sofiagvaladze
2022-12-02 14:40:28 +01:00
parent c7c2959449
commit bfa7a47c86
@@ -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')