| 1 |
|
| 2 |
|
| 3 |
from markupsafe import Markup |
| 4 |
|
| 5 |
from odoo import fields, models, _ |
| 6 |
from odoo.tools.misc import clean_context |
| 7 |
|
| 8 |
|
| 9 |
class SurveyInvite(models.TransientModel): |
| 10 |
_inherit = "survey.invite" |
| 11 |
|
| 12 |
applicant_id = fields.Many2one('hr.applicant', string='Applicant') |
| 13 |
|
| 14 |
def _get_done_partners_emails(self, existing_answers): |
| 15 |
partners_done, emails_done, answers = super()._get_done_partners_emails(existing_answers) |
| 16 |
if self.applicant_id.response_ids.filtered(lambda res: res.survey_id.id == self.survey_id.id): |
| 17 |
if existing_answers and self.existing_mode == 'resend': |
| 18 |
partners_done |= self.applicant_id.partner_id |
| 19 |
return partners_done, emails_done, answers |
| 20 |
|
| 21 |
def _send_mail(self, answer): |
| 22 |
mail = super()._send_mail(answer) |
| 23 |
if answer.applicant_id: |
| 24 |
answer.applicant_id.message_post(body=Markup(mail.body_html)) |
| 25 |
mail.send() |
| 26 |
return mail |
| 27 |
|
| 28 |
def action_invite(self): |
| 29 |
self.ensure_one() |
| 30 |
if self.applicant_id: |
| 31 |
survey = self.survey_id.with_context(clean_context(self.env.context)) |
| 32 |
|
| 33 |
if not self.applicant_id.response_ids.filtered(lambda res: res.survey_id.id == self.survey_id.id): |
| 34 |
self.applicant_id.sudo().write({ |
| 35 |
'response_ids': (self.applicant_id.response_ids | survey.sudo()._create_answer(partner=self.applicant_id.partner_id, |
| 36 |
**self._get_answers_values())).ids |
| 37 |
}) |
| 38 |
|
| 39 |
partner = self.applicant_id.partner_id |
| 40 |
survey_link = survey._get_html_link(title=survey.title) |
| 41 |
partner_link = partner._get_html_link() |
| 42 |
content = _('The survey %(survey_link)s has been sent to %(partner_link)s', |
| 43 |
survey_link=survey_link, |
| 44 |
partner_link=partner_link, |
| 45 |
) |
| 46 |
body = Markup('<p>%s</p>') % content |
| 47 |
self.applicant_id.message_post(body=body) |
| 48 |
return super().action_invite() |