[IMP]hr_employee_stats_sheet:read the planned hours of all the days at once
The planned hours of each day searched the employee calendar history, then the calendar attendances, day by day. The days computed together now share one search of the calendar histories and one of the attendances. The calendar of a day is chosen by the same rule as before, now in ``_select_stats_calendar`` and shared with ``_get_calendar_in_progress_during_a_time_period``: the history line covering the day, else the company calendar, and an error when two lines cover it. Assisted-by: Claude:claude-opus-5-5 Assisted-by: GPT:gpt-6.1-sol Assisted-by: GPT:gpt-6.2-astra-ultrafast
This commit is contained in:
@@ -455,6 +455,41 @@ class TestHrEmployeeStatsRecovery(TransactionCase):
|
||||
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")
|
||||
|
||||
# --- Reading many days at once -----------------------------------------
|
||||
|
||||
def _create_days(self, *days):
|
||||
return self.env['hr.employee.stats'].create([
|
||||
{'employee_id': self.employee.id, 'date': day} for day in days
|
||||
])
|
||||
|
||||
def test_planned_hours_read_together_follow_calendar_history(self):
|
||||
two_weeks = self.env['resource.calendar'].create({
|
||||
'name': 'Alternating Mondays',
|
||||
'two_weeks_calendar': True,
|
||||
'attendance_ids': [
|
||||
(0, 0, {'name': 'Even Monday', 'dayofweek': '0', 'week_type': '0',
|
||||
'hour_from': 9, 'hour_to': 12}),
|
||||
(0, 0, {'name': 'Odd Monday', 'dayofweek': '0', 'week_type': '1',
|
||||
'hour_from': 9, 'hour_to': 14}),
|
||||
],
|
||||
})
|
||||
mondays = ['2025-03-03', '2025-03-10', '2025-03-17', '2025-03-24']
|
||||
self.env['hr.employee.calendar'].create({
|
||||
'employee_id': self.employee.id, 'calendar_id': two_weeks.id,
|
||||
'date_start': mondays[0], 'date_end': mondays[1],
|
||||
})
|
||||
one_day = self.env['hr.employee.calendar'].create({
|
||||
'employee_id': self.employee.id, 'calendar_id': self.base_calendar.id,
|
||||
'date_start': mondays[2], 'date_end': mondays[2],
|
||||
})
|
||||
days = self._create_days(*mondays)
|
||||
# even week, odd week, base calendar, company calendar (8h) after the history
|
||||
self.assertEqual(days.mapped('total_planned_hours'), [3, 5, 7, 8])
|
||||
one_day.date_start = mondays[1] # two calendars on March 10: an anomaly
|
||||
self.env.invalidate_all()
|
||||
with self.assertRaisesRegex(UserError, 'calendar starting'):
|
||||
days.mapped('total_planned_hours')
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestHrEmployeeStatsLeaveAndRecoveryUnit(TransactionCase):
|
||||
|
||||
Reference in New Issue
Block a user