summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAurélien Warnon <awa@odoo.com>2019-02-27 14:28:22 +0000
committerAurélien Warnon <awa@odoo.com>2019-03-08 11:00:06 +0000
commitdb53057528cd0c0c1a7794b2e57b0e355d4e58ec (patch)
treec3697d48330d350d257a3498e436b3d5fbbb63d5
parent1932e25f685315f5d8f813e9c9f74c2382628c02 (diff)
[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.
-rw-r--r--addons/survey/models/survey_survey.py27
-rw-r--r--addons/survey/views/survey_survey_views.xml7
2 files changed, 34 insertions, 0 deletions
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')
@@ -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/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"