[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
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -25,27 +25,35 @@
|
||||
<div class="jumbotron mt32">
|
||||
<h1>Thank you!</h1>
|
||||
<div t-field="survey.thank_you_message" class="oe_no_empty" />
|
||||
<t t-if="survey.scoring_type != 'no_scoring'">
|
||||
<div>You scored <t t-esc="answer.quizz_score" />%</div>
|
||||
<t t-if="answer.quizz_passed">
|
||||
<div>Congratulations, you have passed the test!</div>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<t t-if="survey.scoring_type != 'no_scoring'">
|
||||
<div>You scored <t t-esc="answer.quizz_score" />%</div>
|
||||
<t t-if="answer.quizz_passed">
|
||||
<div>Congratulations, you have passed the test!</div>
|
||||
|
||||
<div t-if="survey.certificate" class="mt16 mb16">
|
||||
<a role="button"
|
||||
class="btn btn-primary btn-lg"
|
||||
t-att-href="'/survey/%s/get_certification' % survey.id">
|
||||
<i class="fa fa-fw fa-trophy" role="img" aria-label="Download certification" title="Download certification"/>
|
||||
Download certification
|
||||
</a>
|
||||
<div t-if="survey.certificate" class="mt16 mb16">
|
||||
<a role="button"
|
||||
class="btn btn-primary btn-lg"
|
||||
t-att-href="'/survey/%s/get_certification' % survey.id">
|
||||
<i class="fa fa-fw fa-trophy" role="img" aria-label="Download certification" title="Download certification"/>
|
||||
Download certification
|
||||
</a>
|
||||
</div>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<div>Unfortunately, you have failed the test.</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-call="survey.retake_survey_button"/>
|
||||
<div t-if="survey.scoring_type != 'scoring_without_answers'">
|
||||
If you wish, you can <a t-att-href="'/survey/print/%s?answer_token=%s&review=True' % (survey.access_token, answer.token)">review your answers</a>
|
||||
</div>
|
||||
</t>
|
||||
<t t-else="">
|
||||
<div>Unfortunately, you have failed the test.</div>
|
||||
</t>
|
||||
</t>
|
||||
<t t-call="survey.retake_survey_button"/>
|
||||
<div t-if="survey.scoring_type != 'scoring_without_answers'">
|
||||
If you wish, you can <a t-att-href="'/survey/print/%s?answer_token=%s&review=True' % (survey.access_token, answer.token)">review your answers</a>
|
||||
</div>
|
||||
<div class="col-6 text-center" t-if="survey.certification_give_badge and answer.quizz_passed">
|
||||
<img t-att-src="'/web/image/gamification.badge/%s/image_medium' % survey.certification_badge_id.id"/>
|
||||
<div>You received the badge <span class="font-weight-bold" t-esc="survey.certification_badge_id.name"/>!</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user