This commit modifies most of the usages of read_group and uses _read_group instead. _read_group doesn't join automatically on the many2one fields when no order_by is specified, making it more performant when the "name" of the many2one is not relevant, which is the case for most back-end cases closes odoo/odoo#84908 Task-id: 2479334 Related: odoo/enterprise#24877 Signed-off-by: Raphael Collet <rco@odoo.com>
17 lines
787 B
Python
17 lines
787 B
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import fields, models
|
|
|
|
|
|
class HrDepartment(models.Model):
|
|
_inherit = 'hr.department'
|
|
|
|
def _compute_expense_sheets_to_approve(self):
|
|
expense_sheet_data = self.env['hr.expense.sheet']._read_group([('department_id', 'in', self.ids), ('state', '=', 'submit')], ['department_id'], ['department_id'])
|
|
result = dict((data['department_id'][0], data['department_id_count']) for data in expense_sheet_data)
|
|
for department in self:
|
|
department.expense_sheets_to_approve_count = result.get(department.id, 0)
|
|
|
|
expense_sheets_to_approve_count = fields.Integer(compute='_compute_expense_sheets_to_approve', string='Expenses Reports to Approve')
|