Consult
Interview
@@ -35,8 +35,7 @@
-
-
+
diff --git a/addons/hr_recruitment_survey/wizard/survey_invite.py b/addons/hr_recruitment_survey/wizard/survey_invite.py
index aba0ada21fe..c24d2d151c6 100644
--- a/addons/hr_recruitment_survey/wizard/survey_invite.py
+++ b/addons/hr_recruitment_survey/wizard/survey_invite.py
@@ -9,14 +9,28 @@ class SurveyInvite(models.TransientModel):
applicant_id = fields.Many2one('hr.applicant', string='Applicant')
+ def _get_done_partners_emails(self, existing_answers):
+ partners_done, emails_done, answers = super()._get_done_partners_emails(existing_answers)
+ if self.applicant_id.response_ids.filtered(lambda res: res.survey_id.id == self.survey_id.id):
+ if existing_answers and self.existing_mode == 'resend':
+ partners_done |= self.applicant_id.partner_id
+ return partners_done, emails_done, answers
+
+ def _send_mail(self, answer):
+ mail = super()._send_mail(answer)
+ if answer.applicant_id:
+ answer.applicant_id.message_post(body=mail.body_html)
+ return mail
+
def action_invite(self):
self.ensure_one()
if self.applicant_id:
survey = self.survey_id.with_context(clean_context(self.env.context))
- if not self.applicant_id.response_id:
+ if not self.applicant_id.response_ids.filtered(lambda res: res.survey_id.id == self.survey_id.id):
self.applicant_id.write({
- 'response_id': survey._create_answer(partner=self.applicant_id.partner_id).id
+ 'response_ids': (self.applicant_id.response_ids | survey._create_answer(partner=self.applicant_id.partner_id,
+ **self._get_answers_values())).ids
})
partner = self.applicant_id.partner_id
diff --git a/addons/survey/models/survey_survey.py b/addons/survey/models/survey_survey.py
index a65dfb734f7..54113a60fc7 100644
--- a/addons/survey/models/survey_survey.py
+++ b/addons/survey/models/survey_survey.py
@@ -902,8 +902,7 @@ class Survey(models.Model):
# ACTIONS
# ------------------------------------------------------------
- def action_send_survey(self):
- """ Open a window to compose an email, pre-filled with the survey message """
+ def check_validity(self):
# Ensure that this survey has at least one question.
if not self.question_ids:
raise UserError(_('You cannot send an invitation for a survey that has no questions.'))
@@ -918,6 +917,10 @@ class Survey(models.Model):
if not self.active:
raise exceptions.UserError(_("You cannot send invitations for closed surveys."))
+ def action_send_survey(self):
+ """ Open a window to compose an email, pre-filled with the survey message """
+ self.check_validity()
+
template = self.env.ref('survey.mail_template_user_input_invite', raise_if_not_found=False)
local_context = dict(
diff --git a/addons/survey/wizard/survey_invite.py b/addons/survey/wizard/survey_invite.py
index cbb81a121ec..604bb6c66b5 100644
--- a/addons/survey/wizard/survey_invite.py
+++ b/addons/survey/wizard/survey_invite.py
@@ -48,7 +48,7 @@ class SurveyInvite(models.TransientModel):
existing_mode = fields.Selection([
('new', 'New invite'), ('resend', 'Resend invite')],
string='Handle existing', default='resend', required=True)
- existing_text = fields.Text('Resend Comment', compute='_compute_existing_text', readonly=True, store=False)
+ existing_text = fields.Text('Resend Comment', compute='_compute_existing_text')
# technical info
mail_server_id = fields.Many2one('ir.mail_server', 'Outgoing mail server')
# survey
@@ -71,30 +71,33 @@ class SurveyInvite(models.TransientModel):
@api.depends('partner_ids', 'survey_id')
def _compute_existing_partner_ids(self):
- self.existing_partner_ids = list(set(self.survey_id.user_input_ids.partner_id.ids) & set(self.partner_ids.ids))
+ for wizard in self:
+ wizard.existing_partner_ids = list(set(wizard.survey_id.user_input_ids.partner_id.ids) & set(wizard.partner_ids.ids))
@api.depends('emails', 'survey_id')
def _compute_existing_emails(self):
- emails = list(set(emails_split.split(self.emails or "")))
- existing_emails = self.survey_id.mapped('user_input_ids.email')
- self.existing_emails = '\n'.join(email for email in emails if email in existing_emails)
+ for wizard in self:
+ emails = list(set(emails_split.split(wizard.emails or "")))
+ existing_emails = wizard.survey_id.mapped('user_input_ids.email')
+ wizard.existing_emails = '\n'.join(email for email in emails if email in existing_emails)
@api.depends('existing_partner_ids', 'existing_emails')
def _compute_existing_text(self):
- existing_text = False
- if self.existing_partner_ids:
- existing_text = '%s: %s.' % (
- _('The following customers have already received an invite'),
- ', '.join(self.mapped('existing_partner_ids.name'))
- )
- if self.existing_emails:
- existing_text = '%s\n' % existing_text if existing_text else ''
- existing_text += '%s: %s.' % (
- _('The following emails have already received an invite'),
- self.existing_emails
- )
+ for wizard in self:
+ existing_text = False
+ if wizard.existing_partner_ids:
+ existing_text = '%s: %s.' % (
+ _('The following customers have already received an invite'),
+ ', '.join(wizard.mapped('existing_partner_ids.name'))
+ )
+ if wizard.existing_emails:
+ existing_text = '%s\n' % existing_text if existing_text else ''
+ existing_text += '%s: %s.' % (
+ _('The following emails have already received an invite'),
+ wizard.existing_emails
+ )
- self.existing_text = existing_text
+ wizard.existing_text = existing_text
@api.depends('survey_id.access_token')
def _compute_survey_start_url(self):
@@ -170,13 +173,23 @@ class SurveyInvite(models.TransientModel):
# ------------------------------------------------------
def _prepare_answers(self, partners, emails):
- answers = self.env['survey.user_input']
existing_answers = self.env['survey.user_input'].search([
'&', ('survey_id', '=', self.survey_id.id),
'|',
('partner_id', 'in', partners.ids),
('email', 'in', emails)
])
+ partners_done, emails_done, answers = self._get_done_partners_emails(existing_answers)
+
+ for new_partner in partners - partners_done:
+ answers |= self.survey_id._create_answer(partner=new_partner, check_attempts=False, **self._get_answers_values())
+ for new_email in [email for email in emails if email not in emails_done]:
+ answers |= self.survey_id._create_answer(email=new_email, check_attempts=False, **self._get_answers_values())
+
+ return answers
+
+ def _get_done_partners_emails(self, existing_answers):
+ answers = self.env['survey.user_input']
partners_done = self.env['res.partner']
emails_done = []
if existing_answers:
@@ -195,13 +208,7 @@ class SurveyInvite(models.TransientModel):
answers |= next(existing_answer for existing_answer in
existing_answers.sorted(lambda answer: answer.create_date, reverse=True)
if existing_answer.email == email_done)
-
- for new_partner in partners - partners_done:
- answers |= self.survey_id._create_answer(partner=new_partner, check_attempts=False, **self._get_answers_values())
- for new_email in [email for email in emails if email not in emails_done]:
- answers |= self.survey_id._create_answer(email=new_email, check_attempts=False, **self._get_answers_values())
-
- return answers
+ return (partners_done, emails_done, answers)
def _get_answers_values(self):
return {
diff --git a/addons/survey/wizard/survey_invite_views.xml b/addons/survey/wizard/survey_invite_views.xml
index 3dc503493a3..4787b922c9a 100644
--- a/addons/survey/wizard/survey_invite_views.xml
+++ b/addons/survey/wizard/survey_invite_views.xml
@@ -32,6 +32,8 @@
}"
placeholder="e.g. 'Rick Sanchez' <rick_sanchez@example.com>, hictor_vugo@example.com"/>
+
+
@@ -43,8 +45,6 @@
Customers will receive a new token and be able to completely retake the survey.
-
-