PURPOSE As new features are about to land in survey, notably live interactions [1] and new survey building [2] performing a pre cleaning is necessary. In this PR we clean survey models by: removing unnecessary fields, cleaning some code and finally renaming models. SPECIFICATIONS: RENAME QUIZ_SCORE ON SURVEY.USER_INPUT On survey.user_input, quiz_score field to scoring_percentage ``quiz_score`` field name is related to the old "quiz" behavior of surveys that is replaced by certifications and scoring mechanisms. Let us propagate the renaming, beginning with a ``scoring_`` prefix. SPECIFICATIONS: RENAME QUIZZ_PASSED ON SURVEY.USER_INPUT on survey.user_input, rename quizz_passed field to scoring_success ``quizz_passed`` field name is related to the old "quiz" behavior of surveys that is replaced by certifications and scoring mechanisms. Let us propagate the renaming, beginning with a ``scoring_`` prefix. SPECIFICATIONS: RENAME TOKEN ON SURVEY.USER_INPUT on survey.user_input, rename token field to access_token Survey user input model holds two token field. One is used to distinguish a pool of attempts linked to a given invite: ``invite_token``. The other one is used to control access to a specific user input. It means that ``invite_token`` indicates a set of user inputs and each of them is accessed through its own ``token``. To be coherent with other naming in odoo this latter field is renamed to ``access_token``. LINKS [0] Related to Task ID 2061901 (survey models cleaning and preparation) [1] Task ID 1972640 (live interactions) [2] Task ID 2119587 (new frontend for building surveys) PR #40765
33 lines
1.4 KiB
Python
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.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
|