From 9e4342fba298e5ac620155ab4fa04de7a4675550 Mon Sep 17 00:00:00 2001 From: Laetitia Da Costa Date: Tue, 30 Dec 2025 14:49:17 +0100 Subject: [PATCH] [FIX]16.0-fix-french-holidays:fix the resource calendar linked to the leave --- l10n_fr_hr_holidays/__manifest__.py | 2 +- l10n_fr_hr_holidays/models/hr_leave.py | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/l10n_fr_hr_holidays/__manifest__.py b/l10n_fr_hr_holidays/__manifest__.py index 21bca26..309a0bb 100644 --- a/l10n_fr_hr_holidays/__manifest__.py +++ b/l10n_fr_hr_holidays/__manifest__.py @@ -3,7 +3,7 @@ { "name": "France - Time Off", - "version": "16.0.1.0.0", + "version": "16.0.1.0.1", "category": "Human Resources/Time Off", "countries": ["fr"], "summary": "Management of leaves for part-time workers in France", diff --git a/l10n_fr_hr_holidays/models/hr_leave.py b/l10n_fr_hr_holidays/models/hr_leave.py index e87ce33..36f1c74 100644 --- a/l10n_fr_hr_holidays/models/hr_leave.py +++ b/l10n_fr_hr_holidays/models/hr_leave.py @@ -2,7 +2,7 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from dateutil.relativedelta import relativedelta -from odoo import fields, models, _ +from odoo import fields, models, _, api from odoo.exceptions import UserError class HrLeave(models.Model): @@ -11,6 +11,13 @@ class HrLeave(models.Model): resource_calendar_id = fields.Many2one('resource.calendar', compute='_compute_resource_calendar_id', store=True, readonly=False, copy=False) l10n_fr_date_to_changed = fields.Boolean() + @api.depends( + 'holiday_type', + 'employee_id', + 'employee_id.resource_calendar_id', + 'request_date_from', + 'request_date_to', + ) def _compute_resource_calendar_id(self): for leave in self: calendar = False @@ -36,6 +43,20 @@ class HrLeave(models.Model): # If there are more than one contract they should all have the # same calendar, otherwise a constraint is violated. calendar = contracts[:1].resource_calendar_id + # Crappy hack again : if hr_employee_calendar_planning is installed + # use planning calendar instead of contract calendar + if 'hr.employee.calendar' in self.env: + calendar_planning = self.env["hr.employee.calendar"].search( + [ + ("employee_id", "=", leave.employee_id.id), + ("date_start", "<=", leave.request_date_to), + "|", ("date_end", "=", False), # pas de date de fin OU + ("date_end", ">=", leave.request_date_from), # date de fin après le début + ], + limit=1, + ) + if calendar_planning: + calendar = calendar_planning.calendar_id elif leave.holiday_type == 'department': calendar = leave.department_id.company_id.resource_calendar_id elif leave.holiday_type == 'company':