From 22e4d3f715d4b068a96a31adcfa02e68da5ddf3f Mon Sep 17 00:00:00 2001 From: Dossogne Bertrand Date: Fri, 3 Nov 2023 10:48:12 +0100 Subject: [PATCH] [FIX] hr_holidays: fix various bugs This commits fixes 3 issues: - Traceback on the creation of a new leave: If the french holidays l10n is installed, creating a new leave was impossible due to an override of a method was not adapted to a change on the base method `_get_duration` - Impossibility to create a leave for more than 1 employee: the validity check was only done for the employee set in employee_id, which was resulting in a traceback if the leave was created for more than one employee. - Wrong error message: Before this commit, the error message given to the employee if the leave isn't possible to create was directed to an employee creating is own leave. As this is not the only way to create a leave, the message has been adapted to reflect every situation. closes odoo/odoo#140886 Signed-off-by: Yannick Tivisse (yti) --- addons/hr_holidays/models/hr_leave.py | 9 +++++---- addons/l10n_fr_hr_holidays/models/hr_leave.py | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index c354e1ed583..a5c3fe9674f 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -749,12 +749,13 @@ Attempting to double-book your time off won't magically make your vacation 2x be leave_type = leave.holiday_status_id if leave_type.requires_allocation == 'no': continue - employee = leave.employee_id + employees = leave._get_employees_from_holiday_type() date_from = leave.date_from.date() - leave_data = leave_type.get_allocation_data(employee, date_from) + leave_data = leave_type.get_allocation_data(employees, date_from) max_excess = leave_type.max_allowed_negative if leave_type.allows_negative else 0 - if leave_data[employee][0][1]['total_virtual_excess'] > max_excess: - raise ValidationError(_("You don't have a valid allocation to cover that request.")) + for employee in employees: + if leave_data[employee][0][1]['total_virtual_excess'] > max_excess: + raise ValidationError(_("There is no valid allocation to cover that request.")) #################################################### # ORM Overrides methods diff --git a/addons/l10n_fr_hr_holidays/models/hr_leave.py b/addons/l10n_fr_hr_holidays/models/hr_leave.py index 3e552b03a9c..098c0e7973f 100644 --- a/addons/l10n_fr_hr_holidays/models/hr_leave.py +++ b/addons/l10n_fr_hr_holidays/models/hr_leave.py @@ -80,7 +80,7 @@ class HrLeave(models.Model): else: leave.l10n_fr_date_to_changed = False - def _get_duration(self, resource_calendar=None): + def _get_duration(self, check_leave_type=True, resource_calendar=None): """ In french time off laws, if an employee has a part time contract, when taking time off before one of his off day (compared to the company's calendar) it should also count the time