Files
odoo_source/addons/survey/models/res_partner.py
T
Vincent Schippefilt 05fc9a6733 [IMP] *: use _read_group instead of read_group
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>
2022-03-02 17:10:48 +00:00

33 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
certifications_count = fields.Integer('Certifications Count', compute='_compute_certifications_count')
certifications_company_count = fields.Integer('Company Certifications Count', compute='_compute_certifications_company_count')
@api.depends('is_company')
def _compute_certifications_count(self):
read_group_res = self.env['survey.user_input'].sudo()._read_group(
[('partner_id', 'in', self.ids), ('scoring_success', '=', True)],
['partner_id'], 'partner_id'
)
data = dict((res['partner_id'][0], res['partner_id_count']) for res in read_group_res)
for partner in self:
partner.certifications_count = data.get(partner.id, 0)
@api.depends('is_company', 'child_ids.certifications_count')
def _compute_certifications_company_count(self):
self.certifications_company_count = sum(child.certifications_count for child in self.child_ids)
def action_view_certifications(self):
action = self.env["ir.actions.actions"]._for_xml_id("survey.res_partner_action_certifications")
action['view_mode'] = 'tree'
action['domain'] = ['|', ('partner_id', 'in', self.ids), ('partner_id', 'in', self.child_ids.ids)]
return action