Files
odoo_source/addons/survey/models/res_partner.py
T
Patrick Hoste 81c7afb833 [IMP] eLearning: adds course and certification stat button on partner
Adds two stats button on res.partner form view :
- The first one will show all the courses that the partner is following.
- The second one will show all the certifications the partner has passed.
When the partner is a company :
- All the courses followed by all the partners are shown without duplicate.
- All the certifications passed by all the partners are shown.

PR : #34908
Task ID : 2034097

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
2019-07-31 09:54:04 +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), ('quizz_passed', '=', 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.ref('survey.res_partner_action_certifications').read()[0]
action['view_mode'] = 'tree'
action['domain'] = ['|', ('partner_id', 'in', self.ids), ('partner_id', 'in', self.child_ids.ids)]
return action