From 3e4b0f320054e2297583355b35449c17541eb589 Mon Sep 17 00:00:00 2001
From: mcm-odoo <mcm@odoo.com>
Date: Fri, 6 Sep 2019 09:26:32 +0000
Subject: [PATCH] [IMP] website_slides: improve slides backend views

This commit improves a bit the existing backend views of the elearning
app (notably propagating content and course labeling instead of slide and
channel) and adds a pivot view for model slide.slide.

FP feedback

Task 2066646
---
 addons/website_slides/models/slide_question.py   |  4 ++--
 addons/website_slides/models/slide_slide.py      |  2 +-
 .../website_slides/views/slide_channel_views.xml |  5 ++---
 .../website_slides/views/slide_slide_views.xml   | 16 ++++++++++++++--
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/addons/website_slides/models/slide_question.py b/addons/website_slides/models/slide_question.py
index adc871c22e24..62daeccf534b 100644
--- a/addons/website_slides/models/slide_question.py
+++ b/addons/website_slides/models/slide_question.py
@@ -8,11 +8,11 @@ from odoo.exceptions import ValidationError
 class SlideQuestion(models.Model):
     _name = "slide.question"
     _rec_name = "question"
-    _description = "Slide Quiz Question"
+    _description = "Content Quiz Question"
 
     sequence = fields.Integer("Sequence", default=10)
     question = fields.Char("Question Name", required=True, translate=True)
-    slide_id = fields.Many2one('slide.slide', string="Slide", required=True)
+    slide_id = fields.Many2one('slide.slide', string="Content", required=True)
     answer_ids = fields.One2many('slide.answer', 'question_id', string="Answer")
     # statistics
     attempts_count = fields.Integer(compute='_compute_statistics', groups='website.group_website_publisher')
diff --git a/addons/website_slides/models/slide_slide.py b/addons/website_slides/models/slide_slide.py
index 9fda90951297..1a99c84129aa 100644
--- a/addons/website_slides/models/slide_slide.py
+++ b/addons/website_slides/models/slide_slide.py
@@ -121,7 +121,7 @@ class Slide(models.Model):
     sequence = fields.Integer('Sequence', default=0)
     user_id = fields.Many2one('res.users', string='Uploaded by', default=lambda self: self.env.uid)
     description = fields.Text('Description', translate=True)
-    channel_id = fields.Many2one('slide.channel', string="Channel", required=True)
+    channel_id = fields.Many2one('slide.channel', string="Course", required=True)
     tag_ids = fields.Many2many('slide.tag', 'rel_slide_tag', 'slide_id', 'tag_id', string='Tags')
     is_preview = fields.Boolean('Allow Preview', default=False, help="The course is accessible by anyone : the users don't need to join the channel to access the content of the course.")
     completion_time = fields.Float('Duration', digits=(10, 4), help="The estimated completion time for this slide")
diff --git a/addons/website_slides/views/slide_channel_views.xml b/addons/website_slides/views/slide_channel_views.xml
index 3a037150c3f4..1c41e55576c6 100644
--- a/addons/website_slides/views/slide_channel_views.xml
+++ b/addons/website_slides/views/slide_channel_views.xml
@@ -57,7 +57,6 @@
                         </div>
                         <div>
                             <field name="active" invisible="1"/>
-                            <label for="tag_ids"/>
                             <field name="tag_ids" widget="many2many_tags" placeholder="Tags"/>
                         </div>
                         <notebook colspan="4">
@@ -67,7 +66,7 @@
                                         <field name="sequence" widget="handle"/>
                                         <field name="name"/>
                                         <field name="slide_type" attrs="{'invisible': [('slide_type', '=', 'category')]}"/>
-                                        <field name="completion_time" attrs="{'invisible': [('slide_type', '=', 'category')]}"/>
+                                        <field name="completion_time" attrs="{'invisible': [('slide_type', '=', 'category')]}" string="Duration" widget="float_time"/>
                                         <field name="total_views" attrs="{'invisible': [('slide_type', '=', 'category')]}"/>
                                         <field name="is_category" invisible="1"/>
                                         <control>
@@ -252,7 +251,7 @@
                                             <button class="btn btn-primary" name="open_website_url" type="object">View course</button>
                                         </div>
                                         <div class="col-6 o_kanban_primary_right">
-                                            <div class="d-flex">
+                                            <div class="d-flex" t-if="record.rating_count.raw_value">
                                                 <a name="action_view_ratings" type="object" class="mr-auto"><field name="rating_count"/> reviews</a>
                                                 <span><field name="rating_avg_stars"/> / 5</span>
                                             </div>
diff --git a/addons/website_slides/views/slide_slide_views.xml b/addons/website_slides/views/slide_slide_views.xml
index a7130a21567e..922a2b3fec0e 100644
--- a/addons/website_slides/views/slide_slide_views.xml
+++ b/addons/website_slides/views/slide_slide_views.xml
@@ -244,7 +244,7 @@
                     <separator/>
                     <filter string="Archived" name="inactive" domain="[('active','=',False)]"/>
                     <group expand="0" string="Group By">
-                        <filter string="Channel" name="groupby_channel" domain="[]" context="{'group_by': 'channel_id'}"/>
+                        <filter string="Course" name="groupby_channel" domain="[]" context="{'group_by': 'channel_id'}"/>
                         <filter string="Category" name="groupby_category" domain="[]" context="{'group_by': 'category_id'}"/>
                         <filter string="Type" name="groupby_type" domain="[]" context="{'group_by': 'slide_type'}"/>
                     </group>
@@ -258,11 +258,23 @@
             <field name="arch" type="xml">
                 <graph string="Graph of Contents" stacked="False">
                     <field name="channel_id" type="row"/>
+                    <field name="slide_type" type="col"/>
                     <field name="total_views" type="measure"/>
                 </graph>
             </field>
         </record>
 
+        <record id="slide_slide_view_pivot" model="ir.ui.view">
+            <field name="name">slide.slide.view.pivot</field>
+            <field name="model">slide.slide</field>
+            <field name="arch" type="xml">
+                <pivot>
+                    <field name="channel_id" type="row"/>
+                    <field name="total_views" type="measure"/>
+                </pivot>
+            </field>
+        </record>
+
         <record id="slide_slide_action" model="ir.actions.act_window">
             <field name="name">Contents</field>
             <field name="res_model">slide.slide</field>
@@ -280,7 +292,7 @@
             <field name="name">Contents</field>
             <field name="type">ir.actions.act_window</field>
             <field name="res_model">slide.slide</field>
-            <field name="view_mode">graph,tree,form</field>
+            <field name="view_mode">graph,tree,form,pivot</field>
             <field name="view_id" ref="slide_slide_view_graph"/>
         </record>
     </data>
-- 
GitLab