Skip to content
Permalink
Browse files

[IMP] survey: Add certification template selection

  • Loading branch information...
qmo-odoo committed Apr 15, 2019
1 parent e8a692b commit 6a75cd211da563b3d6ee3f911425792b12f8b326
@@ -529,9 +529,7 @@ def survey_get_certification(self, survey_id, **kwargs):

if not succeeded_attempt:
raise UserError(_("The user has not succeeded the certification"))

report_sudo = request.env.ref('survey.certification_report').sudo()

report_sudo = request.env.ref(survey.certification_template_id.certification_template_xml_id).sudo()
report = report_sudo.render_qweb_pdf([succeeded_attempt.id], data={'report_type': 'pdf'})[0]
reporthttpheaders = [
('Content-Type', 'application/pdf'),
@@ -20,5 +20,35 @@
<field name="closed" eval="True" />
<field name="fold" eval="True" />
</record>

<!-- Certification report templates -->
<record id="certification_report_view_modern_purple" model="survey.certification.template">
<field name="name">Modern</field>
<field name="certification_template_xml_id">survey.certification_report</field>
</record>
<record id="certification_report_view_modern_blue" model="survey.certification.template">
<field name="name">Modern blue</field>
<field name="color_theme">blue</field>
<field name="certification_template_xml_id">survey.certification_report</field>
</record>
<record id="certification_report_view_modern_gold" model="survey.certification.template">
<field name="name">Modern gold</field>
<field name="color_theme">gold</field>
<field name="certification_template_xml_id">survey.certification_report</field>
</record>
<record id="certification_report_view_classic_purple" model="survey.certification.template">
<field name="name">Classic</field>
<field name="certification_template_xml_id">survey.certification_report_classic</field>
</record>
<record id="certification_report_view_classic_blue" model="survey.certification.template">
<field name="name">Classic blue</field>
<field name="color_theme">blue</field>
<field name="certification_template_xml_id">survey.certification_report_classic</field>
</record>
<record id="certification_report_view_classic_gold" model="survey.certification.template">
<field name="name">Classic gold</field>
<field name="color_theme">gold</field>
<field name="certification_template_xml_id">survey.certification_report_classic</field>
</record>
</data>
</odoo>
@@ -6,3 +6,4 @@
from . import survey_question
from . import survey_stage
from . import survey_user
from . import survey_certification_template
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

import uuid

from collections import Counter, OrderedDict
from itertools import product
from werkzeug import urls
import random

from odoo import api, fields, models, SUPERUSER_ID, _
from odoo.exceptions import UserError
from odoo.osv import expression


class SurveyCertificationTemplate(models.Model):
_name = "survey.certification.template"
_description = "Certification template"
_rec_name = "name"

name = fields.Char(required=True)
survey_id = fields.One2many('survey.survey', "certification_template_id")
certification_template_xml_id = fields.Char(required=True)
color_theme = fields.Char()
@@ -89,6 +89,7 @@ def _get_default_access_token(self):
'mail.template', 'Certification Email Template',
domain="[('model', '=', 'survey.user_input')]",
help="Automated email sent to the user when he succeeds the certification, containing his certification document.")
certification_template_id = fields.Many2one('survey.certification.template', string="Certification template ")

_sql_constraints = [
('access_token_unique', 'unique(access_token)', 'Access token should be unique'),
@@ -23,3 +23,4 @@ access_survey_user_input_line_all,survey.user_input_line.all,model_survey_user_i
access_survey_user_input_line_user,survey.user_input_line.user,model_survey_user_input_line,base.group_user,0,0,0,0
access_survey_user_input_line_survey_user,survey.user_input_line.survey.user,model_survey_user_input_line,group_survey_user,1,1,1,1
access_survey_user_input_line_survey_manager,survey.user_input_line.survey.manager,model_survey_user_input_line,group_survey_manager,1,1,1,1
access_survey_certification_template_all,survey.certification.template.all,model_survey_certification_template,,1,0,0,0
@@ -5,7 +5,7 @@
<t t-call="web.html_container">
<t t-foreach="docs" t-as="user_input">
<!-- Style classes to be applyed to '#o_survey_certification': [no class](purple), gold, blue -->
<div id="o_survey_certification" t-att-data-oe-model="user_input._name" t-att-data-oe-id="user_input.id" class="article certification-wrapper modern">
<div id="o_survey_certification" t-att-data-oe-model="user_input._name" t-att-data-oe-id="user_input.id" t-att-class="'article certification-wrapper modern %s' %(user_input.survey_id.certification_template_id.color_theme)">
<div class="certification">
<div class="certification-top">
<div class="certification-bg-dark">
@@ -44,7 +44,7 @@
<t t-call="web.html_container">
<t t-foreach="docs" t-as="user_input">
<!-- Style classes to be applyed to '#o_survey_certification': [no class](purple), gold, blue -->
<div id="o_survey_certification" t-att-data-oe-model="user_input._name" t-att-data-oe-id="user_input.id" class="article certification-wrapper classic">
<div id="o_survey_certification" t-att-data-oe-model="user_input._name" t-att-data-oe-id="user_input.id" t-att-class="'article certification-wrapper classic %s' %(user_input.survey_id.certification_template_id.color_theme)">
<div class="certification">
<h5 class="certification-name-label">CERTIFICATE</h5>
<div class="certification-name" t-field="user_input.survey_id.display_name"/>
@@ -12,5 +12,16 @@
attachment="'certification.pdf'"
print_report_name="'Certification - %s' % (object.survey_id.display_name)"
/>

<report
id="certification_report_classic"
model="survey.user_input"
string="Certifications"
report_type="qweb-pdf"
name="survey.certification_report_view_classic"
file="survey.certification_report_view_classic"
attachment="'certification.pdf'"
print_report_name="'Certification - %s' % (object.survey_id.display_name)"
/>
</data>
</odoo>
@@ -92,6 +92,7 @@
<field name="passing_score" attrs="{'invisible': [('scoring_type', '=', 'no_scoring')]}" />
<field name="certificate" attrs="{'invisible': [('scoring_type', '=', 'no_scoring')]}" />
<field name="certification_mail_template_id" attrs="{'invisible': [('certificate', '=', False)]}" />
<field name="certification_template_id" attrs="{'invisible': [('certificate', '=', False)]}" />
</group>
</group>
</page>

0 comments on commit 6a75cd2

Please sign in to comment.
You can’t perform that action at this time.