[FIX] hr_recruitment_survey: fix creation of an empty registration
To reproduce an issue:
Open Recruitment Form from Surveys app. Share it with a recipient.
For example with Azure Interior.
Current behavior:
2 registrations are created, including an empty one.
Expected behavior:
Only 1 registration (for Azure Interior) should be created.
Task-2694600
Partial rewrite of odoo/odoo#81851
closes odoo/odoo#81903
X-original-commit: a0a626253b62f01d6bbfe56b98fdedb2317b9598
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
committed by
Thibault Delavallée
parent
d08bc1f350
commit
3bcac60f4b
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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 = '<a href="#" data-oe-model="%s" data-oe-id="%s">%s</a>' % (survey._name, survey.id, survey.title)
|
||||
partner_link = '<a href="#" data-oe-model="%s" data-oe-id="%s">%s</a>' % (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 = '<p>%s</p>' % content
|
||||
self.applicant_id.message_post(body=body)
|
||||
return super().action_invite()
|
||||
|
||||
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user