[FIX] survey: resend survey input=>right one

When we use "Send invitation again" on a survey.user_input, it will send
the first survey.user_input it finds corresponding to:

- the state "new" or "skip",
- the partner it must be sent to,
- the survey the user_input corresponds to,
- the email it must be sent to,

or if none found, it could be create a new one.

This is an okay behavior in most instance, but in the case of
hr_appraisal where a manager could have same survey to fill for
"employee A" and "employee B" and when you send them again, we would receive two
mails linking to the same employee.

With this changeset, the current behavior is kept but when an existing
user_input is resent, we prioritize itself before searching a matching
one.

opw-1934478
closes #30693
This commit is contained in:
Nicolas Lempereur
2019-01-30 13:43:14 +00:00
parent d11a2000c4
commit 006002646e
2 changed files with 5 additions and 0 deletions
+1
View File
@@ -744,6 +744,7 @@ class SurveyUserInput(models.Model):
""" Send again the invitation """
self.ensure_one()
local_context = {
'survey_resent_user_input': self.id,
'survey_resent_token': True,
'default_partner_ids': self.partner_id and [self.partner_id.id] or [],
'default_multi_email': self.email or "",
@@ -135,6 +135,10 @@ class SurveyMailComposeMessage(models.TransientModel):
Mail.create(values).send()
def create_token(wizard, partner_id, email):
if context.get("survey_resent_user_input"):
survey_user_input = SurveyUserInput.browse(context.get("survey_resent_user_input"))
if survey_user_input.state in ('new', 'skip'):
return survey_user_input.token
if context.get("survey_resent_token"):
survey_user_input = SurveyUserInput.search([('survey_id', '=', wizard.survey_id.id),
('state', 'in', ['new', 'skip']), '|', ('partner_id', '=', partner_id),