Skip to content

Commit

Permalink
[REF] survey: add a "_mark_done" method to improve answers state mana…
Browse files Browse the repository at this point in the history
…gement

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#32880

Signed-off-by: Thibault Delavallee (tde) <[email protected]>
  • Loading branch information
awa-odoo committed Apr 23, 2019
1 parent 62533ec commit d6f07e6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
9 changes: 5 additions & 4 deletions addons/hr_skills_survey/models/survey_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
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)])
Expand All @@ -30,7 +32,6 @@ def _send_certification(self):
'display_type': 'certification',
'survey_id': survey.id
})
return super(SurveyUserInput, self)._send_certification()


class ResumeLine(models.Model):
Expand Down
8 changes: 3 additions & 5 deletions addons/survey/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,20 +405,18 @@ def survey_submit(self, survey_token, answer_token, **post):

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'
Expand Down
7 changes: 5 additions & 2 deletions addons/survey/models/survey_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,14 @@ def _compute_is_time_limit_reached(self):
> 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")
Expand Down

0 comments on commit d6f07e6

Please sign in to comment.