summaryrefslogtreecommitdiff
path: root/addons/hr_holidays/models
diff options
context:
space:
mode:
authorYannick Tivisse <yti@odoo.com>2020-11-25 12:50:36 +0000
committerYannick Tivisse <yti@odoo.com>2020-11-25 13:12:49 +0000
commitc0e082ee1fba7cecc711f724974d79ed65bab29b (patch)
treea2fad7d67e0df7f0ec3a90922830ae9d1de73399 /addons/hr_holidays/models
parent26a2c047a2757c600b3128fe753fa1328043a245 (diff)
[FIX] hr_holidays: Remove contraint
Purpose ======= The goal of this contraint is to prevent employees to take a time off when he's not supposed to work (example: after the end of his contract). But, in some conditions (example: we change the contract end date), the number_of_days is not recomputed, and the constraint is raised when unlinking the time off. Move the chunk of code at the validation level, to prevent validating a time off if the employee is not supposed to work. closes odoo/odoo#62323 Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
Diffstat (limited to 'addons/hr_holidays/models')
-rw-r--r--addons/hr_holidays/models/hr_leave.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py
index 5ac1c0b456d..0b0da2d6407 100644
--- a/addons/hr_holidays/models/hr_leave.py
+++ b/addons/hr_holidays/models/hr_leave.py
@@ -549,12 +549,6 @@ class HolidaysRequest(models.Model):
else:
holiday.can_approve = True
- @api.constrains('date_from', 'date_to')
- def _check_number_of_days(self):
- leaves = self.filtered(lambda l: l.employee_id and not l.number_of_days)
- if leaves:
- raise ValidationError(_('The following employees are not supposed to work during that period:\n %s') % ','.join(leaves.mapped('employee_id.name')))
-
@api.constrains('date_from', 'date_to', 'employee_id')
def _check_date(self):
for holiday in self.filtered('employee_id'):
@@ -985,6 +979,10 @@ class HolidaysRequest(models.Model):
def action_validate(self):
current_employee = self.env.user.employee_id
+ leaves = self.filtered(lambda l: l.employee_id and not l.number_of_days)
+ if leaves:
+ raise ValidationError(_('The following employees are not supposed to work during that period:\n %s') % ','.join(leaves.mapped('employee_id.name')))
+
if any(holiday.state not in ['confirm', 'validate1'] and holiday.validation_type != 'no_validation' for holiday in self):
raise UserError(_('Time off request must be confirmed in order to approve it.'))