From ff9c37b08ba05bd4ca19e7da020b5b27e9b6e2e8 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Wed, 10 Apr 2019 12:00:03 +0000 Subject: [PATCH] [IMP] survey : give bagde on survey passed (no cron waiting) To avoid having to wait the cron that distribute badges to elligible users, we run the cron manually at the survey passed if the survey is a certification and if the certification delivers a badge. Task ID : 1935136 PR #31486 --- addons/survey/models/survey_user.py | 17 +++++++-- addons/survey/views/survey_templates.xml | 46 ++++++++++++++---------- 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/addons/survey/models/survey_user.py b/addons/survey/models/survey_user.py index ee291c7b713..4bbee52d030 100644 --- a/addons/survey/models/survey_user.py +++ b/addons/survey/models/survey_user.py @@ -180,11 +180,22 @@ class SurveyUserInput(models.Model): 2. send the certification email with attached document if - The survey is a certification - It has a certification_mail_template_id set - - The user succeeded the test """ + - The user succeeded the test + Will also run challenge Cron to give the certification badge if any.""" self.write({'state': 'done'}) + Challenge = self.env['gamification.challenge'].sudo() + badge_ids = [] for user_input in self: - if user_input.survey_id.certificate and user_input.quizz_passed and user_input.survey_id.certification_mail_template_id: - user_input.survey_id.certification_mail_template_id.send_mail(user_input.id, notif_layout="mail.mail_notification_light") + if user_input.survey_id.certificate and user_input.quizz_passed: + if user_input.survey_id.certification_mail_template_id: + user_input.survey_id.certification_mail_template_id.send_mail(user_input.id, notif_layout="mail.mail_notification_light") + if user_input.survey_id.certification_give_badge: + badge_ids.append(user_input.survey_id.certification_badge_id.id) + + if badge_ids: + challenges = Challenge.search([('reward_id', 'in', badge_ids)]) + if challenges: + Challenge._cron_update(ids=challenges.ids, commit=False) @api.multi def _get_survey_url(self): diff --git a/addons/survey/views/survey_templates.xml b/addons/survey/views/survey_templates.xml index 20426c852ca..605fd56ef60 100644 --- a/addons/survey/views/survey_templates.xml +++ b/addons/survey/views/survey_templates.xml @@ -25,27 +25,35 @@

Thank you!

- -
You scored %
- -
Congratulations, you have passed the test!
+
+
+ +
You scored %
+ +
Congratulations, you have passed the test!
-
- - - Download certification - + + + +
Unfortunately, you have failed the test.
+
+ + +
+ If you wish, you can review your answers
-
- -
Unfortunately, you have failed the test.
-
- - -
- If you wish, you can review your answers +
+
+ +
You received the badge !
+