[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>
This commit is contained in:
@@ -37,6 +37,7 @@ sent mails with personal token for the invitation of the survey.
|
||||
'views/survey_templates.xml',
|
||||
'views/gamification_badge_views.xml',
|
||||
'wizard/survey_invite_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
],
|
||||
'demo': [
|
||||
'data/survey_demo_user.xml',
|
||||
|
||||
@@ -7,3 +7,4 @@ from . import survey_question
|
||||
from . import survey_user
|
||||
from . import badge
|
||||
from . import challenge
|
||||
from . import res_partner
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
# -*- 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
|
||||
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo><data>
|
||||
|
||||
<record id="res_partner_action_certifications" model="ir.actions.act_window">
|
||||
<field name="name">Certifications Succeeded</field>
|
||||
<field name="res_model">survey.user_input</field>
|
||||
<field name="view_mode">tree</field>
|
||||
<field name="context">{'search_default_quizz_passed': 1}</field>
|
||||
</record>
|
||||
|
||||
<record id="res_partner_view_form" model="ir.ui.view">
|
||||
<field name="name">res.partner.view.form.inherit.survey</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="groups_id" eval="[(4, ref('survey.group_survey_user'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<button class="oe_stat_button" type="object"
|
||||
icon="fa-trophy" name="action_view_certifications"
|
||||
attrs="{'invisible': ['|', ('certifications_count', '=', 0), ('is_company', '=', True)]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="certifications_count" /></span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('certifications_count', '<', 2)]}">Certifications</span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('certifications_count', '>', 1)]}">Certification</span>
|
||||
</div>
|
||||
</button>
|
||||
<button class="oe_stat_button" type="object"
|
||||
icon="fa-trophy" name="action_view_certifications"
|
||||
attrs="{'invisible': ['|', ('certifications_company_count', '=', 0), ('is_company', '=', False)]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="certifications_company_count" /></span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('certifications_company_count', '<', 2)]}">Certifications</span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('certifications_company_count', '>', 1)]}">Certification</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
||||
@@ -27,6 +27,7 @@ Featuring
|
||||
'data': [
|
||||
'views/assets.xml',
|
||||
'views/res_config_settings_views.xml',
|
||||
'views/res_partner_views.xml',
|
||||
'views/slide_slide_views.xml',
|
||||
'views/slide_channel_partner_views.xml',
|
||||
'views/slide_channel_views.xml',
|
||||
|
||||
@@ -10,3 +10,4 @@ from . import res_config_settings
|
||||
from . import website
|
||||
from . import res_users
|
||||
from . import res_groups
|
||||
from . import res_partner
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
# -*- 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'
|
||||
|
||||
slide_channels_count = fields.Integer('Course Count', compute='_compute_slide_channels_count')
|
||||
slide_channels_company_count = fields.Integer('Company Course Count', compute='_compute_slide_channels_company_count')
|
||||
|
||||
@api.depends('is_company')
|
||||
def _compute_slide_channels_count(self):
|
||||
read_group_res = self.env['slide.channel.partner'].sudo().read_group(
|
||||
[('partner_id', 'in', self.ids)],
|
||||
['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.slide_channels_count = data.get(partner.id, 0)
|
||||
|
||||
@api.depends('is_company', 'child_ids.slide_channels_count')
|
||||
def _compute_slide_channels_company_count(self):
|
||||
for partner in self:
|
||||
if partner.is_company:
|
||||
partner.slide_channels_company_count = self.env['slide.channel'].sudo().search_count(
|
||||
[('partner_ids', 'in', partner.child_ids.ids)]
|
||||
)
|
||||
else:
|
||||
partner.slide_channels_company_count = 0
|
||||
|
||||
def action_view_courses(self):
|
||||
action = self.env.ref('website_slides.res_partner_action_courses').read()[0]
|
||||
action['view_mode'] = 'tree'
|
||||
action['domain'] = ['|', ('partner_ids', 'in', self.ids), ('partner_ids', 'in', self.child_ids.ids)]
|
||||
|
||||
return action
|
||||
@@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo><data>
|
||||
|
||||
<record id="res_partner_action_courses" model="ir.actions.act_window">
|
||||
<field name="name">Followed Courses</field>
|
||||
<field name="res_model">slide.channel</field>
|
||||
<field name="view_mode">tree</field>
|
||||
</record>
|
||||
|
||||
<record id="res_partner_view_form" model="ir.ui.view">
|
||||
<field name="name">res.partner.view.form.inherit.slides</field>
|
||||
<field name="model">res.partner</field>
|
||||
<field name="inherit_id" ref="base.view_partner_form"/>
|
||||
<field name="groups_id" eval="[(4, ref('website.group_website_publisher'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//div[@name='button_box']" position="inside">
|
||||
<button class="oe_stat_button" type="object"
|
||||
icon="fa-graduation-cap" name="action_view_courses"
|
||||
attrs="{'invisible': ['|', ('slide_channels_count', '=', 0), ('is_company', '=', True)]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="slide_channels_count" /></span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('slide_channels_count', '<', 2)]}">Courses</span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('slide_channels_count', '>', 1)]}">Course</span>
|
||||
</div>
|
||||
</button>
|
||||
<button class="oe_stat_button" type="object"
|
||||
icon="fa-graduation-cap" name="action_view_courses"
|
||||
attrs="{'invisible': ['|', ('slide_channels_company_count', '=', 0), ('is_company', '=', False)]}">
|
||||
<div class="o_field_widget o_stat_info">
|
||||
<span class="o_stat_value"><field name="slide_channels_company_count" /></span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('slide_channels_company_count', '<', 2)]}">Courses</span>
|
||||
<span class="o_stat_text" attrs="{'invisible': [('slide_channels_company_count', '>', 1)]}">Course</span>
|
||||
</div>
|
||||
</button>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data></odoo>
|
||||
Reference in New Issue
Block a user