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 @@

Dear ${object.partner_id.name or 'participant'}

- 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

- Start Survey + % if object.survey_id.certificate: + Start Certification + % else: + Start Survey + % endif
% 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: @@ -503,6 +520,16 @@ class Survey(models.Model): action['context'] = ctx 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') 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"> +
- Start Survey + + Start Certification + + + Start Survey + 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 @@ + @@ -50,7 +51,9 @@ - + + + @@ -76,10 +79,11 @@ - + - + +