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] [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"> +