2 Commits

Author SHA1 Message Date
25e1d6b957 [REF]l10n_fr_hr_holidays:clean up leave days computation
Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m58s
tests / test (pull_request) Successful in 2m25s
- remove unused _round_to_nearest_half
- evaluate _l10n_fr_leave_applies once in _get_number_of_days_batch and
  count working dates without a day-by-day loop
- compute the calendar working hours once per date lookup loop
- move pytz import to the top of resource_calendar.py

No functional change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 11:03:52 +01:00
83f2169647 [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>
2026-11-04 11:02:37 +01:00
2 changed files with 14 additions and 42 deletions

View File

@@ -102,21 +102,18 @@ class HrTimesheetSheet(models.Model):
def _get_working_hours_per_day(self): def _get_working_hours_per_day(self):
""" """
Get the hours per day used to convert recovery hours into allocation days. Get the hours per day for the employee according to:
It must be the same ratio as the one used by Odoo to convert the allocation - the employee's work contract,
days back into hours (see hr.leave.allocation._compute_number_of_hours_display), - or their resource calendar,
otherwise the allocation won't display the recovery hours of the timesheet sheet:
- the employee's resource calendar,
- or the company's resource calendar, - or the company's resource calendar,
- or the default value of 8 hours per day. - or the default value of 8 hours per day.
:return: hours per day :return: hours per day
""" """
self.ensure_one() # get ressource calendar id used during the timesheet sheet time period
return ( ressource_calendar_id = self.employee_id._get_calendar_in_progress_during_a_time_period(self.date_start,self.date_end)
self.employee_id.sudo().resource_calendar_id.hours_per_day if ressource_calendar_id:
or self.company_id.resource_calendar_id.hours_per_day return ressource_calendar_id.hours_per_day
or HOURS_PER_DAY return HOURS_PER_DAY
)
def action_generate_recovery_allocation(self): def action_generate_recovery_allocation(self):
# check if the user has the right to review the timesheet sheet # check if the user has the right to review the timesheet sheet
@@ -150,9 +147,6 @@ class HrTimesheetSheet(models.Model):
# get recovery hours from total gap hours of the timesheet sheet # get recovery hours from total gap hours of the timesheet sheet
recovery_hours = self._get_timesheet_sheet_recovery_hours() recovery_hours = self._get_timesheet_sheet_recovery_hours()
# raise an error if the employee's calendar changes during the timesheet sheet time period
employee_id._get_calendar_in_progress_during_a_time_period(self.date_start, self.date_end)
# convert recovery hours into days # convert recovery hours into days
recovery_days = recovery_hours / self._get_working_hours_per_day() recovery_days = recovery_hours / self._get_working_hours_per_day()

View File

@@ -128,27 +128,8 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
timesheet_sheet.action_generate_recovery_allocation() timesheet_sheet.action_generate_recovery_allocation()
recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)]) recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)])
self.assertEqual(len(recovery_allocation), 1, "There should be one recovery") self.assertEqual(len(recovery_allocation), 1, "There should be one recovery")
self.assertAlmostEqual(recovery_allocation.number_of_hours_display, 6.25, msg="The recovery allocation should display 6.25 hours") self.assertEqual(recovery_allocation.number_of_days,0.8928571428571429, "The recovery allocation should be for 6.25h/7h = 0.8928571428571429 day")
def test_recovery_allocation_hours_with_employee_calendar_different_from_planning(self):
# the employee's resource calendar hours per day differs from the planning calendar one:
# the allocation must still display the recovery hours of the timesheet sheet
self.env['hr.employee.calendar'].create({
'employee_id': self.employee.id,
'date_start': Date.to_date("2025-01-01"),
'date_end': None,
'calendar_id': self.base_calendar.id,
})
self.employee.resource_calendar_id.hours_per_day = 7.3
start_date = date.today() - timedelta(days=date.today().weekday() + 7) # lundi de la semaine dernière
timesheet_sheet = self._create_timesheet_sheet(start_date)
list(self._create_stats(start_date, 5, 8))
self.assertEqual(timesheet_sheet.timesheet_sheet_recovery_hours, 6.25, "timesheet_sheet_recovery_hours should be 6,25",)
timesheet_sheet.action_generate_recovery_allocation()
recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)])
self.assertEqual(len(recovery_allocation), 1, "There should be one recovery")
self.assertAlmostEqual(recovery_allocation.number_of_hours_display, 6.25, msg="The recovery allocation should display 6.25 hours")
def test_negative_recovery_hours(self): def test_negative_recovery_hours(self):
self.env['hr.employee.calendar'].create({ self.env['hr.employee.calendar'].create({
'employee_id': self.employee.id, 'employee_id': self.employee.id,
@@ -172,7 +153,7 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
timesheet_sheet.action_generate_recovery_allocation() timesheet_sheet.action_generate_recovery_allocation()
recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)]) recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)])
self.assertEqual(len(recovery_allocation), 1, "There should be one recovery") self.assertEqual(len(recovery_allocation), 1, "There should be one recovery")
self.assertAlmostEqual(recovery_allocation.number_of_hours_display, -5, msg="The recovery allocation should display -5 hours") self.assertEqual(recovery_allocation.number_of_days, -0.7142857142857143, "The recovery allocation should be for -5/7 hours = −0,714285714")
def test_sheet_totals_update_after_timesheet_change(self): def test_sheet_totals_update_after_timesheet_change(self):
"""Regression test: the sheet totals must reflect the addition and """Regression test: the sheet totals must reflect the addition and
@@ -390,9 +371,7 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
self.assertEqual(timesheet_sheet_1.timesheet_sheet_recovery_hours, 6.25, "timesheet_sheet_recovery_hours should be 6,25",) self.assertEqual(timesheet_sheet_1.timesheet_sheet_recovery_hours, 6.25, "timesheet_sheet_recovery_hours should be 6,25",)
allocation_1 = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet_1.id)]) allocation_1 = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet_1.id)])
self.assertEqual(len(allocation_1), 1, "There should be one recovery") self.assertEqual(len(allocation_1), 1, "There should be one recovery")
# days are computed with the employee's current calendar (9h/day), as Odoo does to display hours self.assertEqual(allocation_1.number_of_days,0.8928571428571429, "The recovery allocation should be for 0.8928571428571429 day")
self.assertAlmostEqual(allocation_1.number_of_days, 6.25 / 9, msg="The recovery allocation should be for 6.25/9 day")
self.assertAlmostEqual(allocation_1.number_of_hours_display, 6.25, msg="The recovery allocation should display 6.25 hours")
#create stats during period of part time calendar for the employee #create stats during period of part time calendar for the employee
# generation 4 stats of 10h each, the employee is supposed to work 9h per day during 4 days # generation 4 stats of 10h each, the employee is supposed to work 9h per day during 4 days
@@ -411,9 +390,8 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
allocation_2 = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet_2.id)]) allocation_2 = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet_2.id)])
self.assertEqual(len(allocation_2), 1, "There should be one recovery") self.assertEqual(len(allocation_2), 1, "There should be one recovery")
self.assertEqual(allocation_2.number_of_days,0.5555555555555556, "The recovery allocation should be for 0,555555556 (5/9) day") self.assertEqual(allocation_2.number_of_days,0.5555555555555556, "The recovery allocation should be for 0,555555556 (5/9) day")
self.assertAlmostEqual(allocation_2.number_of_hours_display, 5, msg="The recovery allocation should display 5 hours")
#check that allocation_1 hasn't changed #check that allocation_1 hasn't changed
self.assertAlmostEqual(allocation_1.number_of_hours_display, 6.25, msg="The recovery allocation should still display 6.25 hours") self.assertEqual(allocation_1.number_of_days,0.8928571428571429, "The recovery allocation should be for 0,892857143 day")
def test_public_holiday(self): def test_public_holiday(self):
self.env['hr.employee.calendar'].create({ self.env['hr.employee.calendar'].create({
@@ -453,7 +431,7 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
timesheet_sheet.action_generate_recovery_allocation() timesheet_sheet.action_generate_recovery_allocation()
recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)]) recovery_allocation = self.env["hr.leave.allocation"].search([("timesheet_sheet_id","=",timesheet_sheet.id)])
self.assertEqual(len(recovery_allocation), 1, "Il doit y avoir une allocation de récupération générée") self.assertEqual(len(recovery_allocation), 1, "Il doit y avoir une allocation de récupération générée")
self.assertAlmostEqual(recovery_allocation.number_of_hours_display, 8.75, msg="The recovery allocation should display 8.75 hours") self.assertEqual(recovery_allocation.number_of_days,1.25, "The recovery allocation should be 1,25 days")
@tagged("post_install", "-at_install") @tagged("post_install", "-at_install")