diff --git a/addons/hr_recruitment_survey/i18n/hr_recruitment_survey.pot b/addons/hr_recruitment_survey/i18n/hr_recruitment_survey.pot index f2a57ec05f2..0049d91a706 100644 --- a/addons/hr_recruitment_survey/i18n/hr_recruitment_survey.pot +++ b/addons/hr_recruitment_survey/i18n/hr_recruitment_survey.pot @@ -264,6 +264,12 @@ msgstr "" msgid "The applicant \"%s\" has finished the survey." msgstr "" +#. module: hr_recruitment_survey +#: code:addons/hr_recruitment_survey/models/survey_invite.py:0 +#, python-format +msgid "The survey %(survey_link)s has been sent to %(partner_link)s" +msgstr "" + #. module: hr_recruitment_survey #: code:addons/hr_recruitment_survey/models/survey_invite.py:0 #, python-format diff --git a/addons/hr_recruitment_survey/models/hr_applicant.py b/addons/hr_recruitment_survey/models/hr_applicant.py index 1a9f4c246c8..2242b77fce7 100644 --- a/addons/hr_recruitment_survey/models/hr_applicant.py +++ b/addons/hr_recruitment_survey/models/hr_applicant.py @@ -31,4 +31,4 @@ class Applicant(models.Model): 'phone': self.partner_phone, 'mobile': self.partner_mobile }) - return self.survey_id.with_context(default_partner_ids=self.partner_id.ids, active_model='hr.applicant', active_id=self.id).action_send_survey() + return self.survey_id.with_context(default_applicant_id=self.id, default_partner_ids=self.partner_id.ids).action_send_survey() diff --git a/addons/hr_recruitment_survey/models/survey_invite.py b/addons/hr_recruitment_survey/models/survey_invite.py index 704845a452f..889aa8612d1 100644 --- a/addons/hr_recruitment_survey/models/survey_invite.py +++ b/addons/hr_recruitment_survey/models/survey_invite.py @@ -1,24 +1,30 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. from odoo import fields, models, _ +from odoo.tools.misc import clean_context class SurveyInvite(models.TransientModel): _inherit = "survey.invite" - applicant_id = fields.Many2one('hr.applicant', string='Applicant', default=lambda self: self.env.context.get('active_id', None) if self.env.context.get('active_model') == 'hr.applicant' else False) + applicant_id = fields.Many2one('hr.applicant', string='Applicant') def action_invite(self): self.ensure_one() - - if self.applicant_id and not self.applicant_id.response_id: - response = self.applicant_id.survey_id._create_answer(partner=self.applicant_id.partner_id) - self.applicant_id.response_id = response.id - if self.applicant_id: - body = _('The survey has been sent to "%s".', self.applicant_id.partner_name) - self.applicant_id.message_post(body=body) + survey = self.survey_id.with_context(clean_context(self.env.context)) + if not self.applicant_id.response_id: + self.applicant_id.write({ + 'response_id': survey._create_answer(partner=self.applicant_id.partner_id).id + }) + + partner = self.applicant_id.partner_id + survey_link = '%s' % (survey._name, survey.id, survey.title) + partner_link = '%s' % (partner._name, partner.id, partner.name) + content = _('The survey %(survey_link)s has been sent to %(partner_link)s', survey_link=survey_link, partner_link=partner_link) + body = '
%s
' % content + self.applicant_id.message_post(body=body) return super().action_invite() diff --git a/addons/hr_recruitment_survey/tests/test_recruitment_survey.py b/addons/hr_recruitment_survey/tests/test_recruitment_survey.py index aa777328c2f..385fc5a12a6 100644 --- a/addons/hr_recruitment_survey/tests/test_recruitment_survey.py +++ b/addons/hr_recruitment_survey/tests/test_recruitment_survey.py @@ -46,17 +46,16 @@ class TestRecruitmentSurvey(common.SingleTransactionCase): action = self.job_sysadmin.action_send_survey() invite_form = Form(self.env[action['res_model']].with_context({ - 'active_id': self.job_sysadmin.id, **action['context'], })) invite = invite_form.save() invite.action_invite() - self.assertEqual(action['context']['active_model'], 'hr.applicant') self.assertEqual(invite.applicant_id, self.job_sysadmin) self.assertNotEqual(self.job_sysadmin.response_id.id, False) answers = Answer.search([('survey_id', '=', self.survey_sysadmin.id)]) self.assertEqual(len(answers), 1) + self.assertEqual(self.job_sysadmin.response_id, answers) self.assertEqual( set(answers.mapped('email')), set([self.job_sysadmin.email_from])) @@ -69,14 +68,3 @@ class TestRecruitmentSurvey(common.SingleTransactionCase): self.job_sysadmin.response_id = self.env['survey.user_input'].create({'survey_id': self.survey_sysadmin.id}) action_print_with_response = self.job_sysadmin.action_print_survey() self.assertIn(self.job_sysadmin.response_id.access_token, action_print_with_response['url']) - - def test_send_survey_no_applicant(self): - action = self.job_sysadmin.action_send_survey() - invite_form = Form(self.env['survey.invite'].with_context({ - **action['context'], - 'active_id': 1, - 'active_model': 'dummy.model', - })) - invite = invite_form.save() - - self.assertFalse(invite.applicant_id, "Should not have an applicant")