[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.
This commit is contained in:
RomainLibert
2018-07-03 17:19:00 +02:00
parent a0c5b58d5d
commit 2d8ba22b4e
@@ -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