diff options
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/survey/data/mail_template_data.xml | 12 | ||||
| -rw-r--r-- | addons/survey/models/survey_survey.py | 31 | ||||
| -rw-r--r-- | addons/survey/models/survey_user.py | 3 | ||||
| -rw-r--r-- | addons/survey/static/src/js/tour_test_certification_failure.js | 4 | ||||
| -rw-r--r-- | addons/survey/static/src/js/tour_test_certification_success.js | 4 | ||||
| -rw-r--r-- | addons/survey/views/survey_survey_views.xml | 7 | ||||
| -rw-r--r-- | addons/survey/views/survey_templates.xml | 7 | ||||
| -rw-r--r-- | addons/survey/views/survey_user_views.xml | 10 |
8 files changed, 65 insertions, 13 deletions
diff --git a/addons/survey/data/mail_template_data.xml b/addons/survey/data/mail_template_data.xml index de05a6a22d9..222d1fbae11 100644 --- a/addons/survey/data/mail_template_data.xml +++ b/addons/survey/data/mail_template_data.xml @@ -9,11 +9,19 @@ <div style="margin: 0px; padding: 0px; font-size: 13px;"> <p style="margin: 0px; padding: 0px; font-size: 13px;"> Dear ${object.partner_id.name or 'participant'}<br/><br/> - We are conducting a survey and your response would be appreciated. + % if object.survey_id.certificate: + You have been invited to take a new certification. + % else: + We are conducting a survey and your response would be appreciated. + % endif <div style="margin: 16px 0px 16px 0px;"> <a href="${('%s?answer_token=%s' % (object.survey_id.public_url, object.token)) | safe}" style="background-color: #875A7B; padding: 8px 16px 8px 16px; text-decoration: none; color: #fff; border-radius: 5px; font-size:13px;"> - Start Survey + % if object.survey_id.certificate: + Start Certification + % else: + Start Survey + % endif </a> </div> % if object.deadline: diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index e486ef9a41c..deb6978d0f7 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -70,6 +70,7 @@ class Survey(models.Model): invite_count = fields.Integer("Invite", compute="_compute_survey_statistic") answer_count = fields.Integer("Started", compute="_compute_survey_statistic") answer_done_count = fields.Integer("Completed", compute="_compute_survey_statistic") + certified_count = fields.Integer("Certified", compute="_compute_certified_count") # scoring and certification fields scoring_type = fields.Selection([ @@ -104,7 +105,7 @@ class Survey(models.Model): @api.depends('user_input_ids.state', 'user_input_ids.test_entry') def _compute_survey_statistic(self): - stat = dict.fromkeys(self.ids, {'invite_count': 0, 'answer_count': 0, 'answer_done_count': 0}) + stat = dict((cid, dict(invite_count=0, answer_count=0, answer_done_count=0)) for cid in self.ids) UserInput = self.env['survey.user_input'] base_domain = ['&', ('survey_id', 'in', self.ids), ('test_entry', '!=', True)] @@ -119,6 +120,22 @@ class Survey(models.Model): for survey in self: survey.update(stat[survey.id]) + @api.depends('certificate', 'user_input_ids.quizz_passed', 'user_input_ids.test_entry') + def _compute_certified_count(self): + stat = dict((cid, 0) for cid in self.ids) + certificate_surveys = self.filtered(lambda survey: survey.certificate) + if certificate_surveys: + read_group_res = self.env['survey.user_input'].read_group( + [('survey_id', 'in', certificate_surveys.ids), ('test_entry', '!=', True), ('quizz_passed', '=', True)], + [], + ['survey_id'] + ) + for item in read_group_res: + stat[item['survey_id'][0]] += item['survey_id_count'] + + for survey in self: + survey.certified_count = stat.get(survey.id, 0) + def _compute_survey_url(self): """ Computes a public URL for the survey """ base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') @@ -434,7 +451,7 @@ class Survey(models.Model): def action_send_survey(self): """ Open a window to compose an email, pre-filled with the survey message """ # Ensure that this survey has at least one page with at least one question. - if not self.page_ids or not [page.question_ids for page in self.page_ids if page.question_ids]: + if (not self.page_ids and self.questions_layout != 'page_per_question') or not self.question_ids: raise UserError(_('You cannot send an invitation for a survey that has no questions.')) if self.stage_id.closed: @@ -504,6 +521,16 @@ class Survey(models.Model): return action @api.multi + def action_survey_user_input_certified(self): + action_rec = self.env.ref('survey.action_survey_user_input_notest') + action = action_rec.read()[0] + ctx = dict(self.env.context) + ctx.update({'search_default_survey_id': self.ids[0], + 'search_default_quizz_passed': 1}) + action['context'] = ctx + return action + + @api.multi def action_survey_user_input_invite(self): action_rec = self.env.ref('survey.action_survey_user_input_notest') action = action_rec.read()[0] diff --git a/addons/survey/models/survey_user.py b/addons/survey/models/survey_user.py index 86d810ca588..e49d1314731 100644 --- a/addons/survey/models/survey_user.py +++ b/addons/survey/models/survey_user.py @@ -32,6 +32,7 @@ class SurveyUserInput(models.Model): # description survey_id = fields.Many2one('survey.survey', string='Survey', required=True, readonly=True, ondelete='cascade') + scoring_type = fields.Selection(string="Scoring", related="survey_id.scoring_type") start_datetime = fields.Datetime('Start date and time', readonly=True) is_time_limit_reached = fields.Boolean("Is time limit reached?", compute='_compute_is_time_limit_reached') input_type = fields.Selection([ @@ -58,7 +59,7 @@ class SurveyUserInput(models.Model): question_ids = fields.Many2many('survey.question', string='Predefined Questions', readonly=True) deadline = fields.Datetime('Deadline', help="Datetime until customer can open the survey and submit answers") - quizz_score = fields.Float("Score for the quiz (%)", compute="_compute_quizz_score", default=0.0) + quizz_score = fields.Float("Score (%)", compute="_compute_quizz_score") # Stored for performance reasons while displaying results page quizz_passed = fields.Boolean('Quizz Passed', compute='_compute_quizz_passed', store=True, compute_sudo=True) diff --git a/addons/survey/static/src/js/tour_test_certification_failure.js b/addons/survey/static/src/js/tour_test_certification_failure.js index 395e6b23990..baebb64864d 100644 --- a/addons/survey/static/src/js/tour_test_certification_failure.js +++ b/addons/survey/static/src/js/tour_test_certification_failure.js @@ -9,8 +9,8 @@ odoo.define('survey.tour_test_certification_failure', function (require) { var tour = require('web_tour.tour'); var failSteps = [{ // Page-1 - content: "Clicking on Start Survey", - trigger: 'a.btn.btn-primary.btn-lg:contains("Start Survey")', + content: "Clicking on Start Certification", + trigger: 'a.btn.btn-primary.btn-lg:contains("Start Certification")', }, { // Question: Do we sell Acoustic Bloc Screens? content: "Selecting answer 'No'", trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") select', diff --git a/addons/survey/static/src/js/tour_test_certification_success.js b/addons/survey/static/src/js/tour_test_certification_success.js index 9d0d7d4ec33..39108e1b7a4 100644 --- a/addons/survey/static/src/js/tour_test_certification_success.js +++ b/addons/survey/static/src/js/tour_test_certification_success.js @@ -8,8 +8,8 @@ tour.register('test_certification_success', { url: '/survey/start/4ead4bc8-b8f2-4760-a682-1fde8ddb95ac' }, [{ // Page-1 - content: "Clicking on Start Survey", - trigger: 'a.btn.btn-primary.btn-lg:contains("Start Survey")', + content: "Clicking on Start Certification", + trigger: 'a.btn.btn-primary.btn-lg:contains("Start Certification")', }, { // Question: Do we sell Acoustic Bloc Screens? content: "Selecting answer 'Yes'", trigger: 'div.js_question-wrapper:contains("Do we sell Acoustic Bloc Screens") select', diff --git a/addons/survey/views/survey_survey_views.xml b/addons/survey/views/survey_survey_views.xml index 35833af5fef..43a7a44c26c 100644 --- a/addons/survey/views/survey_survey_views.xml +++ b/addons/survey/views/survey_survey_views.xml @@ -24,6 +24,13 @@ icon="fa-envelope-o"> <field string="Invitations" name="invite_count" widget="statinfo"/> </button> + <button name="action_survey_user_input_certified" + type="object" + class="oe_stat_button" + attrs="{'invisible': [('certificate', '=', False)]}" + icon="fa-trophy"> + <field string="Certified" name="certified_count" widget="statinfo"/> + </button> <button name="action_survey_user_input_completed" type="object" class="oe_stat_button" diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index e5f13cf766f..cbef0daac68 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -178,7 +178,12 @@ </p> </div> <a role="button" class="btn btn-primary btn-lg" t-att-href="'/survey/fill/%s/%s' % (survey.access_token, answer.token)"> - Start Survey + <t t-if="survey.certificate"> + Start Certification + </t> + <t t-else=""> + Start Survey + </t> </a> </div> </div> diff --git a/addons/survey/views/survey_user_views.xml b/addons/survey/views/survey_user_views.xml index f7a58249125..205ba2ee709 100644 --- a/addons/survey/views/survey_user_views.xml +++ b/addons/survey/views/survey_user_views.xml @@ -16,6 +16,7 @@ <separator/> <filter string="Invite" name="invite" domain="[('input_type', '=', 'link')]"/> <separator/> + <filter string="Quizz passed" name="quizz_passed" domain="[('quizz_passed','=', True)]"/> <filter string="Test Entries" name="test" domain="[('test_entry','=', True)]"/> <group expand="0" string="Group By"> <filter name="group_by_survey" string="Survey" domain="[]" context="{'group_by': 'survey_id'}"/> @@ -50,7 +51,9 @@ <field name="partner_id"/> <field name="email" widget="email"/> <field name="test_entry" groups="base.group_no_one"/> - <field name="quizz_score" groups="base.group_no_one"/> + <field name="scoring_type" invisible="1"/> + <field name="quizz_score" attrs="{'invisible': [('scoring_type', '=', 'no_scoring')]}"/> + <field name="quizz_passed" attrs="{'invisible': [('scoring_type', '=', 'no_scoring')]}"/> </group> </group> <field name="user_input_line_ids" mode="tree" attrs="{'readonly': False}"> @@ -76,10 +79,11 @@ <field name="deadline"/> <field name="partner_id"/> <field name="email"/> - <field name="input_type"/> + <field name="input_type" groups="base.group_no_one"/> <field name="state"/> <field name="test_entry" invisible="True"/> - <field name="quizz_score" groups="base.group_no_one"/> + <field name="quizz_passed"/> + <field name="quizz_score"/> </tree> </field> </record> |
