[FIX] hr_holidays: keep company calendar if several employees

Steps to reproduce:
-------------------
- modify the company calendar to get an other value than 8 average hour per day;
- add this calendar to two employees (A and B);
- create a type of leave for the current company;
- create an allocation for the employee A for this type with X hours without saving;
- add the employee B;

Issue:
------
The number of hours is modified.

Cause:
------
There is an inconsistency between `_compute_number_of_hours_display`
and `_compute_from_holiday_status_id` methods.

In the `_compute_from_holiday_status_id` the number of hours is determined
according to order: employee calendar --> company calendar --> constant (8 hours)

In the `_compute_number_of_hours_display` the number of hours directly falls back on
the constant if we don't find an employee for a type of leave that is employee.

In the case of multiple employees, we will always use this constant,
whereas we use the company calendar in the other method.

Solution:
---------
Keep the company calendar if you don't have an employee before falling back on a constant.

opw-3617281

closes odoo/odoo#146730

X-original-commit: 55f24b4f07eaa4527559a2819e264b4809a6b21f
Signed-off-by: Sofie Gvaladze (sgv) <sgv@odoo.com>
Signed-off-by: Thomas Lefebvre (thle) <thle@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-12-19 08:12:30 +00:00
parent 7e902f8cef
commit 9b9e900dad
@@ -225,7 +225,7 @@ class HolidaysAllocation(models.Model):
def _compute_number_of_hours_display(self):
for allocation in self:
allocation_calendar = allocation.holiday_status_id.company_id.resource_calendar_id
if allocation.holiday_type == 'employee':
if allocation.holiday_type == 'employee' and allocation.employee_id:
allocation_calendar = allocation.employee_id.sudo().resource_calendar_id
allocation.number_of_hours_display = allocation.number_of_days * (allocation_calendar.hours_per_day or HOURS_PER_DAY)