From 2d8ba22b4ea63e17db7acd910b749b3ff6839583 Mon Sep 17 00:00:00 2001 From: RomainLibert Date: Fri, 22 Jun 2018 14:17:53 +0200 Subject: [PATCH] [FIX] hr_holidays: add a constraint on interval numbers Before that commit we could ask for an accrual allocation of 0 hours every 0 weeks for instance. As it means nothing to ask for this, we add an sql constraint on these fields and a default value of 1. --- addons/hr_holidays/models/hr_leave_allocation.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 987f5256246..fabb77751cb 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -103,8 +103,8 @@ class HolidaysAllocation(models.Model): can_approve = fields.Boolean('Can Approve', compute='_compute_can_approve') type_request_unit = fields.Selection(related='holiday_status_id.request_unit') accrual = fields.Boolean("Accrual", related='holiday_status_id.accrual', store=True, readonly=True) - number_per_interval = fields.Float("Number of unit per interval", readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}) - interval_number = fields.Integer("Number of unit between two intervals", readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}) + number_per_interval = fields.Float("Number of unit per interval", readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, default=1) + interval_number = fields.Integer("Number of unit between two intervals", readonly=True, states={'draft': [('readonly', False)], 'confirm': [('readonly', False)]}, default=1) unit_per_interval = fields.Selection([ ('hours', 'Hour(s)'), ('days', 'Day(s)') @@ -120,6 +120,8 @@ class HolidaysAllocation(models.Model): ('type_value', "CHECK( (holiday_type='employee' AND employee_id IS NOT NULL) or (holiday_type='category' AND category_id IS NOT NULL) or (holiday_type='department' AND department_id IS NOT NULL) )", "The employee, department or employee category of this request is missing. Please make sure that your user login is linked to an employee."), ('date_check', "CHECK ( number_of_days_temp >= 0 )", "The number of days must be greater than 0."), + ('number_per_interval_check', "CHECK(number_per_interval > 0)", "The number per interval should be greater than 0"), + ('interval_number_check', "CHECK(interval_number > 0)", "The interval number should be greater than 0"), ] @api.model