From eb45f84128124fffb18e893043fc2882419d5ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Wed, 27 Feb 2019 15:18:48 +0000 Subject: [PATCH 1/5] [FIX] survey: fix invitation sending with no page_ids Puprose ======= This commit fixes the survey to allow sending invitation even if the survey has no pages as long as the questions_layout is 'page_per_question'. --- addons/survey/models/survey_survey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index e486ef9a41c..a6b106e1531 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -434,7 +434,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: From 92141334f870a4d253da53e7ef3abcd7894d11bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Wed, 27 Feb 2019 13:47:33 +0000 Subject: [PATCH 2/5] [FIX] survey: fix survey statistics computation Purpose ======= This commit fixes the shared dict in the survey statistics computation that causes surveys to incorrectly share the same stats when computed in batch. --- addons/survey/models/survey_survey.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index a6b106e1531..c49aa846de4 100644 --- a/addons/survey/models/survey_survey.py +++ b/addons/survey/models/survey_survey.py @@ -104,7 +104,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)] From 1932e25f685315f5d8f813e9c9f74c2382628c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Wed, 27 Feb 2019 13:37:06 +0000 Subject: [PATCH 3/5] [IMP] survey: show the quizz_passed field in the answers views Purpose ======= The quizz_passed field is now more important because it determines whether a certification has been successfully taken or not. This commit adds the quizz_passed field in: - The search view of user_input - The list view of user_input - The form view of user_input (along with the score) --- addons/survey/models/survey_user.py | 3 ++- addons/survey/views/survey_user_views.xml | 10 +++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) 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/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 @@ - + - + + From db53057528cd0c0c1a7794b2e57b0e355d4e58ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Warnon?= Date: Wed, 27 Feb 2019 14:28:22 +0000 Subject: [PATCH 4/5] [IMP] survey: add a stat button on survey to show the certified count Purpose ======= This commit adds a stat button on the survey form view showing the amount of answers with the quizz_passed field set to True. It allows to quickly see people that have been granted the certification. On click, the stat button redirects to the answers list view with the "Quizz passed" filter defaulted to True. --- addons/survey/models/survey_survey.py | 27 +++++++++++++++++++++ addons/survey/views/survey_survey_views.xml | 7 ++++++ 2 files changed, 34 insertions(+) diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py index c49aa846de4..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([ @@ -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') @@ -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/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"> +