From 9b9e900dad5a54da0f4df37bb80898e063b0f0f1 Mon Sep 17 00:00:00 2001 From: "Thomas Lefebvre (thle)" Date: Mon, 11 Dec 2023 14:50:51 +0100 Subject: [PATCH] [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) Signed-off-by: Thomas Lefebvre (thle) --- addons/hr_holidays/models/hr_leave_allocation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/hr_holidays/models/hr_leave_allocation.py b/addons/hr_holidays/models/hr_leave_allocation.py index 75807316027..2b276690345 100644 --- a/addons/hr_holidays/models/hr_leave_allocation.py +++ b/addons/hr_holidays/models/hr_leave_allocation.py @@ -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)