From 12eb45301f6692ed466d196abe4e49cb0a6b13d2 Mon Sep 17 00:00:00 2001
From: "Tiffany Chang (tic)"
Date: Mon, 23 Dec 2019 14:16:26 +0000
Subject: [PATCH] [IMP] website_slides_survey: add survey course visibility
Previously there was no way to view when a survey (specifically a
certification survey) was being used by a course from the survey
app. We handle 2 cases for when a survey is currently assigned to
a course:
1. A survey is assigned to 1 course => survey form stat button visible to bring user
directly to corresponding course form.
2. A survey is assigned to more than 1 course (unlikely, but currently possible) =>
survey form stat button visible to show user a list of corresponding courses where
each list entry can be clicked on to view corresponding course form.
Note: we do not cover viewing courses a survey was previously assigned to as this would
be currently be unreasonable to track.
closes odoo/odoo#42336
Task: 2153743
Signed-off-by: Thibault Delavallee (tde)
---
.../models/survey_survey.py | 36 ++++++++++++++++++-
.../views/survey_survey_views.xml | 20 ++++++++++-
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/addons/website_slides_survey/models/survey_survey.py b/addons/website_slides_survey/models/survey_survey.py
index 6cc5b857069..98dc3e6a776 100644
--- a/addons/website_slides_survey/models/survey_survey.py
+++ b/addons/website_slides_survey/models/survey_survey.py
@@ -1,12 +1,46 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
-from odoo import models
+from odoo import api, fields, models, _
class Survey(models.Model):
_inherit = 'survey.survey'
+ slide_ids = fields.One2many(
+ 'slide.slide', 'survey_id', string="Certification Slides",
+ help="The slides this survey is linked to through the e-learning application")
+ slide_channel_ids = fields.One2many(
+ 'slide.channel', string="Certification Courses", compute='_compute_slide_channel_data',
+ help="The courses this survey is linked to through the e-learning application",
+ groups='website_slides.group_website_slides_officer')
+ slide_channel_count = fields.Integer("Courses Count", compute='_compute_slide_channel_data', groups='website_slides.group_website_slides_officer')
+
+ @api.depends('slide_ids.channel_id')
+ def _compute_slide_channel_data(self):
+ for survey in self:
+ survey.slide_channel_ids = survey.slide_ids.mapped('channel_id')
+ survey.slide_channel_count = len(survey.slide_channel_ids)
+
+ # ---------------------------------------------------------
+ # Actions
+ # ---------------------------------------------------------
+
+ def action_survey_view_slide_channels(self):
+ action = self.env.ref('website_slides.slide_channel_action_overview').read()[0]
+ action['display_name'] = _("Courses")
+ if self.slide_channel_count == 1:
+ action.update({'views': [(False, 'form')],
+ 'res_id': self.slide_channel_ids[0].id})
+ else:
+ action.update({'views': [[False, 'tree'], [False, 'form']],
+ 'domain': [('id', 'in', self.slide_channel_ids.ids)]})
+ return action
+
+ # ---------------------------------------------------------
+ # Business
+ # ---------------------------------------------------------
+
def _check_answer_creation(self, user, partner, email, test_entry=False, check_attempts=True, invite_token=False):
""" Overridden to allow website_slides_officer to test certifications. """
self.ensure_one()
diff --git a/addons/website_slides_survey/views/survey_survey_views.xml b/addons/website_slides_survey/views/survey_survey_views.xml
index 87eda55e778..5028c8c15a9 100644
--- a/addons/website_slides_survey/views/survey_survey_views.xml
+++ b/addons/website_slides_survey/views/survey_survey_views.xml
@@ -25,4 +25,22 @@
-
\ No newline at end of file
+
+
+ survey.survey.view.form.inherit.website_slides
+ survey.survey
+
+
+
+
+
+
+
+