[FIX]l10n_fr_hr_holidays:skip public holidays when looking for the return day of part-time employees
When the next scheduled working day of a part-time employee after the leave is a public holiday, the leave end date was not postponed to the day before the actual return, so company working days in between were not counted (e.g. Wed PM-Fri employee, leave 23/12 -> 31/12 with 01/01 being a Friday: 6 days counted instead of 9). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from datetime import date
|
||||
|
||||
from odoo.tests.common import TransactionCase, tagged
|
||||
|
||||
@tagged('post_install_l10n', 'post_install', '-at_install', 'french_leaves')
|
||||
@@ -619,3 +621,65 @@ class TestFrenchLeaves(TransactionCase):
|
||||
self.assertEqual(leave.number_of_days, 5.0,
|
||||
'The number of days should be 5 (14/07 excluded as public holiday).')
|
||||
leave.unlink()
|
||||
|
||||
def test_public_holiday_postpones_return_day(self):
|
||||
# Company works Mon-Sat. Employee works Wed afternoon, Thu and Fri.
|
||||
# Public holidays: 25/12/2020 (Fri), 26/12/2020 (Sat), 01/01/2021 (Fri).
|
||||
# Leave requested from Wed 23/12/2020 to Thu 31/12/2020.
|
||||
# The next scheduled working day (Fri 01/01) is a public holiday, so the
|
||||
# employee only comes back on Wed 06/01/2021: the leave must be extended
|
||||
# to Tue 05/01/2021.
|
||||
# Company working days excluding public holidays:
|
||||
# 23, 24, 28, 29, 30, 31/12 and 02, 04, 05/01 = 9 days
|
||||
company_calendar = self.env['resource.calendar'].create({
|
||||
'name': 'Company Calendar 6d/week',
|
||||
'company_id': self.company.id,
|
||||
'tz': 'Europe/Paris',
|
||||
'attendance_ids': [
|
||||
(0, 0, {'name': 'Morning %s' % d, 'dayofweek': str(d), 'hour_from': 9, 'hour_to': 12.5, 'day_period': 'morning'})
|
||||
for d in range(6)
|
||||
] + [
|
||||
(0, 0, {'name': 'Afternoon %s' % d, 'dayofweek': str(d), 'hour_from': 13.5, 'hour_to': 17, 'day_period': 'afternoon'})
|
||||
for d in range(6)
|
||||
],
|
||||
})
|
||||
employee_calendar = self.env['resource.calendar'].create({
|
||||
'name': 'Employee Calendar Wed PM-Fri',
|
||||
'company_id': self.company.id,
|
||||
'tz': 'Europe/Paris',
|
||||
'attendance_ids': [
|
||||
(0, 0, {'name': 'Wednesday Afternoon', 'dayofweek': '2', 'hour_from': 13.5, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Thursday Morning', 'dayofweek': '3', 'hour_from': 9, 'hour_to': 12.5, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Thursday Afternoon', 'dayofweek': '3', 'hour_from': 13.5, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
(0, 0, {'name': 'Friday Morning', 'dayofweek': '4', 'hour_from': 9, 'hour_to': 12.5, 'day_period': 'morning'}),
|
||||
(0, 0, {'name': 'Friday Afternoon', 'dayofweek': '4', 'hour_from': 13.5, 'hour_to': 17, 'day_period': 'afternoon'}),
|
||||
],
|
||||
})
|
||||
self.company.resource_calendar_id = company_calendar
|
||||
self._set_employee_calendar(employee_calendar)
|
||||
self.employee.tz = 'Europe/Paris'
|
||||
|
||||
for name, day in [('Noel', '2020-12-25'), ('Saint Etienne', '2020-12-26'), ('Jour de l an', '2021-01-01')]:
|
||||
self.env['resource.calendar.leaves'].create({
|
||||
'name': name,
|
||||
'calendar_id': False,
|
||||
'company_id': self.company.id,
|
||||
'date_from': '%s 06:00:00' % day,
|
||||
'date_to': '%s 18:00:00' % day,
|
||||
})
|
||||
|
||||
leave = self.env['hr.leave'].create({
|
||||
'name': 'Test holiday before return',
|
||||
'holiday_status_id': self.time_off_type.id,
|
||||
'employee_id': self.employee.id,
|
||||
'request_date_from': '2020-12-23',
|
||||
'request_date_to': '2020-12-31',
|
||||
'employee_company_id': self.company.id,
|
||||
'resource_calendar_id': self.employee.resource_calendar_id.id,
|
||||
})
|
||||
leave._compute_date_from_to()
|
||||
self.assertEqual(leave.date_to.date(), date(2021, 1, 5),
|
||||
'The leave should be extended until the day before the return (05/01/2021).')
|
||||
self.assertEqual(leave.number_of_days, 9.0,
|
||||
'The number of days should be 9.')
|
||||
leave.unlink()
|
||||
|
||||
Reference in New Issue
Block a user