From 006002646ef04815a0c496d3cdd76de2f8ba2a56 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Wed, 30 Jan 2019 13:03:34 +0000 Subject: [PATCH] [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 --- addons/survey/models/survey.py | 1 + addons/survey/wizard/survey_email_compose_message.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/addons/survey/models/survey.py b/addons/survey/models/survey.py index 95a1cc1fdd1..91730d88b88 100644 --- a/addons/survey/models/survey.py +++ b/addons/survey/models/survey.py @@ -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 "", diff --git a/addons/survey/wizard/survey_email_compose_message.py b/addons/survey/wizard/survey_email_compose_message.py index f57cc226b6c..375499ae512 100644 --- a/addons/survey/wizard/survey_email_compose_message.py +++ b/addons/survey/wizard/survey_email_compose_message.py @@ -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),