Skip to content
Permalink
Browse files

[IMP] survey: Add certification template selection

This commit adds the possibility to select a template
for the certification document downloadable by the user after
succeeding at a certification

Task: 1967652
PR: #32675
  • Loading branch information...
qmo-odoo committed Apr 15, 2019
1 parent e8a692b commit ad9b2bf036175c53fac2061831099afb533c6779
@@ -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_view_modern</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_view_modern</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_view_modern</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_view_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_view_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_view_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,23 @@
# -*- 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)
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", default=lambda self: self.env.ref('survey.certification_report_view_modern_purple'), required=True)

_sql_constraints = [
('access_token_unique', 'unique(access_token)', 'Access token should be unique'),
@@ -23,3 +23,5 @@ 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_survey_user,survey.certification.template.survey.user,model_survey_certification_template,group_survey_user,1,1,1,1
access_survey_certification_template_survey_manager,survey.certification.template.survey.manager,model_survey_certification_template,group_survey_manager,1,1,1,1
@@ -1,72 +1,72 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<template id="certification_report_view">
<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 class="certification">
<div class="certification-top">
<div class="certification-bg-dark">
<div class="certification-company-wrapper" t-field="user_input.survey_id.create_uid.company_id.logo" t-options="{'widget': 'image'}" role="img"/>
</div>
<div class="certification-name" t-field="user_input.survey_id.display_name"/>
</div>
<template id="certification_report_view_modern">
<!-- 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" 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">
<div class="certification-company-wrapper" t-field="user_input.survey_id.create_uid.company_id.logo" t-options="{'widget': 'image'}" role="img"/>
</div>
<div class="certification-name" t-field="user_input.survey_id.display_name"/>
</div>

<div class="certification-bottom">
<h5 class="user-name-label">This Certificate is Presented to</h5>
<div class="user-name" t-esc="user_input.partner_id.name or user_input.email"/>
<div class="certification-bottom">
<h5 class="user-name-label">This Certificate is Presented to</h5>
<div class="user-name" t-esc="user_input.partner_id.name or user_input.email"/>

<div class="certification-description">
<span t-field="user_input.survey_id.create_uid.company_id.display_name"/> is proud to award this certificate to
<span t-esc="user_input.partner_id.name or user_input.email"/> for gratuating from <span t-field="user_input.survey_id.display_name"/>.
</div>
<div class="certification-description">
<span t-field="user_input.survey_id.create_uid.company_id.display_name"/> is proud to award this certificate to
<span t-esc="user_input.partner_id.name or user_input.email"/> for gratuating from <span t-field="user_input.survey_id.display_name"/>.
</div>

<div class="certification-bottom-group">
<div class="certification-bg-dark"/>
<div class="certification-date">
<h5>Date</h5>
<h5 t-field="user_input.create_date" t-options='{"widget": "date"}'/>
</div>
<div class="certification-seal">
<img src="/survey/static/src/img/certification_seal.svg" alt="Certification Seal" role="image"/>
</div>
</div>
<div class="certification-bottom-group">
<div class="certification-bg-dark"/>
<div class="certification-date">
<h5>Date</h5>
<h5 t-field="user_input.create_date" t-options='{"widget": "date"}'/>
</div>
<div class="certification-seal">
<img src="/survey/static/src/img/certification_seal.svg" alt="Certification Seal" role="image"/>
</div>
</div>
</div>
</t>
</t>
</div>
</div>
</template>

<template id="certification_report_view_classic">
<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 class="certification">
<h5 class="certification-name-label">CERTIFICATE</h5>
<div class="certification-name" t-field="user_input.survey_id.display_name"/>
<hr/>
<!-- 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" 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"/>
<hr/>

<h5>This Certificate is Presented to</h5>
<div class="user-name" t-esc="user_input.partner_id.name or user_input.email"/>
<hr class="small"/>
<h5>This Certificate is Presented to</h5>
<div class="user-name" t-esc="user_input.partner_id.name or user_input.email"/>
<hr class="small"/>

<div class="certification-description">
<span t-field="user_input.survey_id.create_uid.company_id.display_name"/> is proud to award this certificate to
<span t-esc="user_input.partner_id.name or user_input.email"/> for gratuating from <span t-field="user_input.survey_id.display_name"/>.
</div>
<div class="certification-description">
<span t-field="user_input.survey_id.create_uid.company_id.display_name"/> is proud to award this certificate to
<span t-esc="user_input.partner_id.name or user_input.email"/> for gratuating from <span t-field="user_input.survey_id.display_name"/>.
</div>

<div class="certification-date" t-field="user_input.create_date" t-options='{"widget": "date"}'/>
<img src="/survey/static/src/img/certification_seal.svg" alt="Certification Seal" role="img"/>
<div class="certification-date" t-field="user_input.create_date" t-options='{"widget": "date"}'/>
<img src="/survey/static/src/img/certification_seal.svg" alt="Certification Seal" role="img"/>

<div class="certificate-signature">
<span t-field="user_input.survey_id.create_uid.company_id.logo" t-options="{'widget': 'image'}" role="img"/>
</div>
</div>
<div class="certificate-signature">
<span t-field="user_input.survey_id.create_uid.company_id.logo" t-options="{'widget': 'image'}" role="img"/>
</div>
</div>
</div>
</template>

<template id="certification_report_view">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="user_input">
<t t-call="{{user_input.survey_id.certification_template_id.certification_template_xml_id}}"/>
</t>
</t>
</template>
@@ -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" options="{'no_create_edit': True, 'no_open':True}" attrs="{'invisible': [('certificate', '=', False)]}" />
</group>
</group>
</page>

0 comments on commit ad9b2bf

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