Files
odoo_source/addons/website_slides_survey/models/survey_survey.py
T
Thibault Delavallée d5b688956b [IMP] survey: display a list-kanban when being ungrouped
PURPOSE

When dealing with lot of surveys kanban view is not really optimal and its
state based grouping is not really helpful. Indeed we do not have total of
each coumn and there is not point adding new states, meaning most surveys
hang in the same column. This is not an optimal display.

SPECIFICATIONS

Improve ungrouped display as this is the main usage of surveys. It should
be displayed like a global list view: each card should take the whole
screen (like ``Visitor`` kanban view). Each line contains some "columns"
holding statistics. We notably use a progressbar to display a nice passed
ratio, as well as a many2one avatar widget to make survey enters the era
of amazing wow kanban views.

When grouped, display should be the old one, aka a standard card.

This is done using a small CSS hack: card template actually consists in main
templates related to two displays. Each card style is hidden depending on being
groups or ungrouped. This triggers a class that is used using CSS to hide
irrelevant content.

A ribbon is also added on kanban cards displaying an Archived danger ribbon
when survey is not active anymore. It is therefore coherent with the form
view display that also has a ribbon defined.

An override in website_slides_survey is added to add number of courses using
the survey.

Order is updated so that new surveys are on top. No need to be bloated by
old ongoing surveys when creating new one.

Finally, some labelling is done with answers to be clearer: registered (number
of raw user inputs), completed (finished answers), certified or passed (quiz
with certification activated or not).

Task-2388785

Part-of: odoo/odoo#77227
2021-11-24 14:04:20 +00:00

74 lines
3.5 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import ast
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
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)
@api.ondelete(at_uninstall=False)
def _unlink_except_linked_to_course(self):
slides = self.slide_ids.filtered(lambda slide: slide.slide_type == "certification").exists()
if slides:
raise ValidationError(_("The Certification '%(certification_name)s' cannot be deleted because it is still being used by the Course(s) '%(courses_names)s'",
certification_name=self.title,
courses_names=', '.join(slides.mapped('channel_id.name'))))
# ---------------------------------------------------------
# Actions
# ---------------------------------------------------------
def action_survey_view_slide_channels(self):
""" Redirect to the channels using the survey as a certification. Open
in no-create as link between those two comes through a slide, hard to
keep as default values. """
action = self.env["ir.actions.actions"]._for_xml_id("website_slides.slide_channel_action_overview")
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)]})
action['context'] = dict(
ast.literal_eval(action.get('context') or '{}'), # sufficient in most cases
create=False
)
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()
if test_entry and user.has_group('website_slides.group_website_slides_officer'):
return True
return super(Survey, self)._check_answer_creation(user, partner, email, test_entry=test_entry, check_attempts=check_attempts, invite_token=invite_token)
def _prepare_challenge_category(self):
slide_survey = self.env['slide.slide'].search([('survey_id', '=', self.id)])
return 'slides' if slide_survey else 'certification'