[FIX] survey: fix detect duplicate partner invitation

When sending the same survey to the same partner, the system detects it and
allows the user to choose between sending a new invitation or resending the
old one so that the user can continue the survey that might already be ongoing.
The detection was not working anymore and this fixes the problem.

Technical note: _compute_existing_partner_ids was intersecting record set
partner_ids (the one currently added) and a record set of partner for which an
invitation has already been sent. The intersection didn't work because
partner_ids relation was not completely set and instead of id, had "origin" id.
Comparing id using a filter solves the problem (using the trick that .ids,
return also the origin ids).

Task-3087702

closes odoo/odoo#111687

X-original-commit: fea798047118f0a482dc2421d92e73f51dd04816
Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
Signed-off-by: Dufays Pierre-Yves (pydu) <pydu@odoo.com>
This commit is contained in:
Pierre-Yves Dufays
2023-02-03 06:05:56 +01:00
parent 4083e08ad9
commit 95911e2b7f
2 changed files with 12 additions and 2 deletions
+11
View File
@@ -84,6 +84,17 @@ class TestSurveyInvite(common.TestSurveyCommon):
self.assertEqual(answers.mapped('partner_id'), self.customer)
self.assertEqual(set(answers.mapped('deadline')), set([deadline]))
with self.subTest('Warning when inviting an already invited partner'):
action = self.survey.action_send_survey()
invite_form = Form(self.env[action['res_model']].with_context(action['context']))
invite_form.send_email = True
invite_form.partner_ids.add(self.customer)
self.assertIn(self.customer, invite_form.existing_partner_ids)
self.assertEqual(invite_form.existing_text,
'The following customers have already received an invite: Caroline Customer.')
@users('survey_manager')
def test_survey_invite_authentication_nosignup(self):
Answer = self.env['survey.user_input']
+1 -2
View File
@@ -71,8 +71,7 @@ class SurveyInvite(models.TransientModel):
@api.depends('partner_ids', 'survey_id')
def _compute_existing_partner_ids(self):
existing_answers = self.survey_id.user_input_ids
self.existing_partner_ids = existing_answers.mapped('partner_id') & self.partner_ids
self.existing_partner_ids = list(set(self.survey_id.user_input_ids.partner_id.ids) & set(self.partner_ids.ids))
@api.depends('emails', 'survey_id')
def _compute_existing_emails(self):