[IMP]hr_employee_stats_sheet:read the validated leaves of all the days in one search

Each day ran two searches on the leaves, one for the recoveries and one
for the other leaves. The days computed together now share one search,
and ``_absence_hours_by_stat`` applies the existing rule to each day: a
single-day request counts the hours Odoo computed for it, a day inside a
longer request counts the planned hours of that day.

The leaves of a day stay in the search order (``date_from desc``), so the
sums are the same as before.

Assisted-by: Claude:claude-opus-5-5
Assisted-by: GPT:gpt-6.2-sol-ultrafast
This commit is contained in:
Valentin Lab
2026-11-19 14:09:25 +01:00
parent 21cca44604
commit 92dc0e2a58
2 changed files with 63 additions and 45 deletions

View File

@@ -706,6 +706,22 @@ class TestHrEmployeeStatsLeaveAndRecoveryUnit(TransactionCase):
self.assertEqual(stat.total_leave_hours, 0, "recovery must not count as a leave")
self.assertEqual(stat.total_recovery_hours, 7, "it must count as a recovery")
def test_leaves_read_together(self):
leave_type = self._create_leave_type('hour')
self.recovery_type.request_unit = 'half_day'
wednesday = self.tuesday + timedelta(days=1)
thursday = self.tuesday + timedelta(days=2)
self._create_leave(self.recovery_type, self.monday, self.monday, half=True, period='am')
self._create_leave(leave_type, self.monday, self.monday, hours=True, hour_from='13', hour_to='15')
self._create_leave(self._create_leave_type('day'), self.tuesday, wednesday)
days = self.env['hr.employee.stats'].create([
{'employee_id': self.employee.id, 'date': day}
for day in (self.monday, self.tuesday, wednesday, thursday)
])
self.env.invalidate_all()
self.assertEqual(days.mapped('total_recovery_hours'), [3, 0, 0, 0])
self.assertEqual(days.mapped('total_leave_hours'), [2, 7, 7, 0])