[IMP]hr_employee_stats_sheet:compute the days of all the sheets together
Reading the totals of several timesheet sheets computed their days sheet by sheet. The days of all the sheets are now computed in one batch first, so a list or a grouped view of sheets needs as many SQL queries for 2 sheets as for 200. Assisted-by: Claude:claude-opus-5-5 Assisted-by: GPT:gpt-6.2-astra-ultrafast
This commit is contained in:
@@ -26,18 +26,19 @@ class HrTimesheetSheet(models.Model):
|
||||
|
||||
@api.depends("employee_stats_ids.gap_hours", "employee_id")
|
||||
def _compute_hours(self):
|
||||
# compute the days of all the sheets together, not sheet by sheet
|
||||
self._stats_through_today().mapped("gap_hours")
|
||||
for sheet in self:
|
||||
sheet.timesheet_sheet_gap_hours = sheet._get_timesheet_sheet_gap_hours()
|
||||
sheet.timesheet_sheet_recovery_hours = sheet._get_timesheet_sheet_recovery_hours()
|
||||
|
||||
def _stats_through_today(self):
|
||||
today = fields.Date.today()
|
||||
return self.mapped("employee_stats_ids").filtered(lambda stat: stat.date <= today)
|
||||
|
||||
def _get_timesheet_sheet_gap_hours(self):
|
||||
self.ensure_one()
|
||||
timesheet_sheet_gap_hours = sum(
|
||||
self.employee_stats_ids.filtered(
|
||||
lambda stat: stat.date <= fields.Date.today()
|
||||
).mapped("gap_hours")
|
||||
)
|
||||
return timesheet_sheet_gap_hours
|
||||
return sum(self._stats_through_today().mapped("gap_hours"))
|
||||
|
||||
def _get_timesheet_sheet_recovery_hours(self):
|
||||
self.ensure_one()
|
||||
|
||||
Reference in New Issue
Block a user