Currently, when you click the stat button "x Courses" on a contact, you land on the dashboard of the courses that this user follows. But this information in not much useful here. You'd like to see information like progress of this member for each courses, or when the member was last active on a specific course. With this commit, when you click the 'x Courses' stat button from a contact, you will see the list view of model 'slide.channel.partner', having the default filter for the contact from which you clicked the button. This will show the additional and relevant information you need, and by removing the filter, you'll be able to see info about all the attendees and their progress on courses they follow (Note that here if the partner is a company, you won't get default filter set but the records will be filtered by domain, because we need to show courses of current contact and it's children, and so we have to set domain in action, instead of adding default filter in action context). The same way, on the Attendees View of a course (when seeing attendees from the course dashboard), we add 'Last Action' field, and instead of fixed domain, we use filter to view attendees of a particular course, removing which can allow us to view information about all the attendees from all courses. We also introduce new 'Attendees' menu under 'eLearning > Reporting' that will show information about all the attendees from all courses, with a default group of channels Task Id-2409447 closes odoo/odoo#64152 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
72 lines
3.2 KiB
Python
72 lines
3.2 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'
|
|
|
|
slide_channel_ids = fields.Many2many(
|
|
'slide.channel', 'slide_channel_partner', 'partner_id', 'channel_id',
|
|
string='eLearning Courses', groups="website_slides.group_website_slides_officer")
|
|
slide_channel_completed_ids = fields.One2many(
|
|
'slide.channel', string='Completed Courses',
|
|
compute='_compute_slide_channel_completed_ids',
|
|
search='_search_slide_channel_completed_ids',
|
|
groups="website_slides.group_website_slides_officer")
|
|
slide_channel_count = fields.Integer(
|
|
'Course Count', compute='_compute_slide_channel_count',
|
|
groups="website_slides.group_website_slides_officer")
|
|
slide_channel_company_count = fields.Integer(
|
|
'Company Course Count', compute='_compute_slide_channel_company_count',
|
|
groups="website_slides.group_website_slides_officer")
|
|
|
|
def _compute_slide_channel_completed_ids(self):
|
|
for partner in self:
|
|
partner.slide_channel_completed_ids = self.env['slide.channel.partner'].search([
|
|
('partner_id', '=', partner.id),
|
|
('completed', '=', True)
|
|
]).mapped('channel_id')
|
|
|
|
def _search_slide_channel_completed_ids(self, operator, value):
|
|
cp_done = self.env['slide.channel.partner'].sudo().search([
|
|
('channel_id', operator, value),
|
|
('completed', '=', True)
|
|
])
|
|
return [('id', 'in', cp_done.partner_id.ids)]
|
|
|
|
@api.depends('is_company')
|
|
def _compute_slide_channel_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_channel_count = data.get(partner.id, 0)
|
|
|
|
@api.depends('is_company', 'child_ids.slide_channel_count')
|
|
def _compute_slide_channel_company_count(self):
|
|
for partner in self:
|
|
if partner.is_company:
|
|
partner.slide_channel_company_count = self.env['slide.channel'].sudo().search_count(
|
|
[('partner_ids', 'in', partner.child_ids.ids)]
|
|
)
|
|
else:
|
|
partner.slide_channel_company_count = 0
|
|
|
|
def action_view_courses(self):
|
|
""" View partners courses. In singleton mode, return courses followed
|
|
by all its contacts (if company) or by himself (if not a company).
|
|
Otherwise simply set a domain on required partners. """
|
|
action = self.env["ir.actions.actions"]._for_xml_id("website_slides.slide_channel_partner_action")
|
|
action['name'] = _('Followed Courses')
|
|
if len(self) == 1 and self.is_company:
|
|
action['domain'] = [('partner_id', 'in', self.child_ids.ids)]
|
|
elif len(self) == 1:
|
|
action['context'] = {'search_default_partner_id': self.id}
|
|
else:
|
|
action['domain'] = [('partner_id', 'in', self.ids)]
|
|
return action
|