From bc3a01b325034c159b82c9d846ef129bee9c36e4 Mon Sep 17 00:00:00 2001 From: Alvaro Fuentes Date: Wed, 12 Jan 2022 10:05:57 +0000 Subject: [PATCH] [FIX] maintenance: `MemoryError` on compute When computing the todo fields of maintenance requests, we could get a `MemoryError` since we are fetching more fields that we actually need. Here we rework the way the compute is done in order to avoid too much prefetch. closes odoo/odoo#82662 X-original-commit: 510831013ba081edd83191a01d562485b6ceca38 Signed-off-by: Christophe Simonis --- addons/maintenance/models/maintenance.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/addons/maintenance/models/maintenance.py b/addons/maintenance/models/maintenance.py index 702271eefb7..003d7a5a2ca 100644 --- a/addons/maintenance/models/maintenance.py +++ b/addons/maintenance/models/maintenance.py @@ -430,12 +430,12 @@ class MaintenanceTeam(models.Model): @api.depends('request_ids.stage_id.done') def _compute_todo_requests(self): for team in self: - team.todo_request_ids = team.request_ids.filtered(lambda e: e.stage_id.done==False) + team.todo_request_ids = self.env['maintenance.request'].search([('maintenance_team_id', '=', team.id), ('stage_id.done', '=', False)]) team.todo_request_count = len(team.todo_request_ids) - team.todo_request_count_date = len(team.todo_request_ids.filtered(lambda e: e.schedule_date != False)) - team.todo_request_count_high_priority = len(team.todo_request_ids.filtered(lambda e: e.priority == '3')) - team.todo_request_count_block = len(team.todo_request_ids.filtered(lambda e: e.kanban_state == 'blocked')) - team.todo_request_count_unscheduled = len(team.todo_request_ids.filtered(lambda e: not e.schedule_date)) + team.todo_request_count_date = self.env['maintenance.request'].search_count([('maintenance_team_id', '=', team.id), ('schedule_date', '!=', False)]) + team.todo_request_count_high_priority = self.env['maintenance.request'].search_count([('maintenance_team_id', '=', team.id), ('priority', '=', '3')]) + team.todo_request_count_block = self.env['maintenance.request'].search_count([('maintenance_team_id', '=', team.id), ('kanban_state', '=', 'blocked')]) + team.todo_request_count_unscheduled = self.env['maintenance.request'].search_count([('maintenance_team_id', '=', team.id), ('schedule_date', '=', False)]) @api.depends('equipment_ids') def _compute_equipment(self):