From d70af67954241c6bb75b341c9997ee536d3d632b Mon Sep 17 00:00:00 2001 From: Anjali Date: Tue, 13 Apr 2021 07:22:35 +0000 Subject: [PATCH] [IMP] website_slides: show relevant info while viewing partners' courses 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) --- addons/website_slides/models/res_partner.py | 12 +++- addons/website_slides/models/slide_channel.py | 25 ++++--- .../views/slide_channel_partner_views.xml | 67 +++++++++++++++++-- .../views/website_slides_menu_views.xml | 9 ++- .../views/website_slides_menu_views.xml | 2 +- 5 files changed, 95 insertions(+), 20 deletions(-) diff --git a/addons/website_slides/models/res_partner.py b/addons/website_slides/models/res_partner.py index 54fd52e96d4..7787e7d3b70 100644 --- a/addons/website_slides/models/res_partner.py +++ b/addons/website_slides/models/res_partner.py @@ -57,7 +57,15 @@ class ResPartner(models.Model): partner.slide_channel_company_count = 0 def action_view_courses(self): - action = self.env["ir.actions.actions"]._for_xml_id("website_slides.slide_channel_action_overview") + """ 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') - action['domain'] = ['|', ('partner_ids', 'in', self.ids), ('partner_ids', 'in', self.child_ids.ids)] + 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 diff --git a/addons/website_slides/models/slide_channel.py b/addons/website_slides/models/slide_channel.py index 52568a5415d..60e74c019b6 100644 --- a/addons/website_slides/models/slide_channel.py +++ b/addons/website_slides/models/slide_channel.py @@ -26,6 +26,12 @@ class ChannelUsersRelation(models.Model): completed_slides_count = fields.Integer('# Completed Slides') partner_id = fields.Many2one('res.partner', index=True, required=True, ondelete='cascade') partner_email = fields.Char(related='partner_id.email', readonly=True) + # channel-related information (for UX purpose) + channel_user_id = fields.Many2one('res.users', string='Responsible', related='channel_id.user_id') + channel_type = fields.Selection(related='channel_id.channel_type') + channel_visibility = fields.Selection(related='channel_id.visibility') + channel_enroll = fields.Selection(related='channel_id.enroll') + channel_website_id = fields.Many2one('website', string='Website', related='channel_id.website_id') def _recompute_completion(self): read_group_res = self.env['slide.slide.partner'].sudo().read_group( @@ -517,21 +523,22 @@ class Channel(models.Model): # Business / Actions # --------------------------------------------------------- - def action_redirect_to_members(self, state=None): + def action_redirect_to_members(self, completed=False): + """ Redirects to attendees of the course. If completed is True, a filter + will be added in action that will display only attendees who have completed + the course. """ action = self.env["ir.actions.actions"]._for_xml_id("website_slides.slide_channel_partner_action") - action['domain'] = [('channel_id', 'in', self.ids)] + action_ctx = {'active_test': False} + if completed: + action_ctx['search_default_filter_completed'] = 1 if len(self) == 1: action['display_name'] = _('Attendees of %s', self.name) - action['context'] = {'active_test': False, 'default_channel_id': self.id} - if state: - action['domain'] += [('completed', '=', state == 'completed')] + action_ctx['search_default_channel_id'] = self.id + action['context'] = action_ctx return action - def action_redirect_to_running_members(self): - return self.action_redirect_to_members('running') - def action_redirect_to_done_members(self): - return self.action_redirect_to_members('completed') + return self.action_redirect_to_members(completed=True) def action_channel_invite(self): self.ensure_one() diff --git a/addons/website_slides/views/slide_channel_partner_views.xml b/addons/website_slides/views/slide_channel_partner_views.xml index 8b88417d96b..1ea66f1ef0d 100644 --- a/addons/website_slides/views/slide_channel_partner_views.xml +++ b/addons/website_slides/views/slide_channel_partner_views.xml @@ -9,6 +9,11 @@ + + + + + @@ -18,21 +23,71 @@ slide.channel.partner - - - - - + + + + + + + + + +