[REF] survey: add a "_mark_done" method to improve answers state management
As other modules than survey (namely hr_skills) now need a hook to add specific behavior when a survey answer is marked as 'done', we removed the '_send_certification' method and replaced it with a '_mark_done' method. It will make it easier to override this method as it has a more generic meaning. closes odoo/odoo#32880 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -8,12 +8,14 @@ from odoo.tools import html2plaintext
|
||||
class SurveyUserInput(models.Model):
|
||||
_inherit = 'survey.user_input'
|
||||
|
||||
def _send_certification(self):
|
||||
def _mark_done(self):
|
||||
""" Will add certification to employee's resumé if
|
||||
- The survey is a certification
|
||||
- The user is linked to an employee
|
||||
- The user succeeded the test
|
||||
At the end, super is call to send by mail"""
|
||||
- The user succeeded the test """
|
||||
|
||||
super(SurveyUserInput, self)._mark_done()
|
||||
|
||||
certificate_user_inputs = self.filtered(lambda user_input: user_input.survey_id.certificate and user_input.quizz_passed)
|
||||
partner_has_completed = {user_input.partner_id.id: user_input.survey_id for user_input in certificate_user_inputs}
|
||||
employees = self.env['hr.employee'].sudo().search([('user_id.partner_id', 'in', certificate_user_inputs.mapped('partner_id').ids)])
|
||||
@@ -30,7 +32,6 @@ class SurveyUserInput(models.Model):
|
||||
'display_type': 'certification',
|
||||
'survey_id': survey.id
|
||||
})
|
||||
return super(SurveyUserInput, self)._send_certification()
|
||||
|
||||
|
||||
class ResumeLine(models.Model):
|
||||
|
||||
@@ -405,20 +405,18 @@ class Survey(http.Controller):
|
||||
|
||||
if answer_sudo.is_time_limit_reached or survey_sudo.questions_layout == 'one_page':
|
||||
go_back = False
|
||||
answer_sudo._send_certification()
|
||||
vals = {'state': 'done'}
|
||||
answer_sudo._mark_done()
|
||||
else:
|
||||
go_back = post['button_submit'] == 'previous'
|
||||
next_page, last = request.env['survey.survey'].next_page_or_question(answer_sudo, page_or_question_id, go_back=go_back)
|
||||
vals = {'last_displayed_page_id': page_or_question_id}
|
||||
|
||||
if next_page is None and not go_back:
|
||||
answer_sudo._send_certification()
|
||||
vals.update({'state': 'done'})
|
||||
answer_sudo._mark_done()
|
||||
else:
|
||||
vals.update({'state': 'skip'})
|
||||
answer_sudo.write(vals)
|
||||
|
||||
answer_sudo.write(vals)
|
||||
ret['redirect'] = '/survey/fill/%s/%s' % (survey_sudo.access_token, answer_token)
|
||||
if go_back:
|
||||
ret['redirect'] += '?prev=prev'
|
||||
|
||||
@@ -137,11 +137,14 @@ class SurveyUserInput(models.Model):
|
||||
> user_input.start_datetime + relativedelta(minutes=user_input.survey_id.time_limit)
|
||||
|
||||
@api.multi
|
||||
def _send_certification(self):
|
||||
""" Will send the certification email with attached document if
|
||||
def _mark_done(self):
|
||||
""" This method will:
|
||||
1. mark the state as 'done'
|
||||
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 """
|
||||
self.write({'state': 'done'})
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user