[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) <yti@odoo.com>
This commit is contained in:
Dossogne Bertrand
2023-11-04 03:25:42 +00:00
parent ef75711fb2
commit 22e4d3f715
2 changed files with 6 additions and 5 deletions
+5 -4
View File
@@ -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
@@ -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