diff options
| author | Aurélien Warnon <awa@odoo.com> | 2019-04-23 12:05:29 +0000 |
|---|---|---|
| committer | Aurélien Warnon <awa@odoo.com> | 2019-04-23 12:05:29 +0000 |
| commit | d6f07e659d245731dc812854aa454ebcdbca9441 (patch) | |
| tree | aa7bc39aead959d79aa45a6b520b84a5c0a3085c /addons | |
| parent | 62533ec752b1ba711e91219880b3efb6a4f1b491 (diff) | |
[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>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/hr_skills_survey/models/survey_user.py | 9 | ||||
| -rw-r--r-- | addons/survey/controllers/main.py | 8 | ||||
| -rw-r--r-- | addons/survey/models/survey_user.py | 7 |
3 files changed, 13 insertions, 11 deletions
diff --git a/addons/hr_skills_survey/models/survey_user.py b/addons/hr_skills_survey/models/survey_user.py index 43e85b40cca..730e7ce82bc 100644 --- a/addons/hr_skills_survey/models/survey_user.py +++ b/addons/hr_skills_survey/models/survey_user.py @@ -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): diff --git a/addons/survey/controllers/main.py b/addons/survey/controllers/main.py index 56f00eb287c..e8552c45b7a 100644 --- a/addons/survey/controllers/main.py +++ b/addons/survey/controllers/main.py @@ -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' diff --git a/addons/survey/models/survey_user.py b/addons/survey/models/survey_user.py index e49d1314731..b4da8b0d4b8 100644 --- a/addons/survey/models/survey_user.py +++ b/addons/survey/models/survey_user.py @@ -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") |
