[FIX]16.0-fix-french-holidays:fix the resource calendar linked to the leave
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m32s

This commit is contained in:
2025-12-30 14:49:17 +01:00
parent 01cf81e8bb
commit 9e4342fba2
2 changed files with 23 additions and 2 deletions

View File

@@ -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",

View File

@@ -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':