[FIX] survey: fix email sent multiples time
Issue
- Install Survey & Contacts
- Have 2 contacts with the same email address
(e.g. test@example.com)
- Create a survey, send it only to that
email address
Email sent 2 times
Cause
When looking for partners linked
to that email address, we do not
provide any limit so the system
send the email to all partners
found.
Solution
If I set one email address,
I expect one email to be sent.
So, the solution would be to
apply a limit of 1 when login
is not required.
OPW-2247693
closes odoo/odoo#51155
X-original-commit: 55b1cc3108d6b672f10ece26db7e13a65ff655d3
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Signed-off-by: Jason Van Malder (jvm) <jvm@odoo.com>
This commit is contained in:
@@ -194,3 +194,30 @@ class TestSurveyInvite(common.TestSurveyCommon):
|
||||
set(answers.mapped('email')),
|
||||
set([self.user_emp.email]))
|
||||
self.assertEqual(answers.mapped('partner_id'), self.user_emp.partner_id)
|
||||
|
||||
def test_survey_invite_token_by_email_nosignup(self):
|
||||
"""
|
||||
Case: have multiples partners with the same email address
|
||||
If I set one email address, I expect one email to be sent
|
||||
"""
|
||||
|
||||
first_partner = self.env['res.partner'].create({
|
||||
'name': 'Test 1',
|
||||
'email': 'test@example.com',
|
||||
})
|
||||
|
||||
self.env['res.partner'].create({
|
||||
'name': 'Test 2',
|
||||
'email': '"Raoul Poilvache" <TEST@example.COM>',
|
||||
})
|
||||
|
||||
self.survey.write({'access_mode': 'token', 'users_login_required': False})
|
||||
action = self.survey.action_send_survey()
|
||||
invite_form = Form(self.env[action['res_model']].with_context(action['context']))
|
||||
invite_form.emails = 'test@example.com'
|
||||
invite = invite_form.save()
|
||||
invite.action_invite()
|
||||
|
||||
answers = self.env['survey.user_input'].search([('survey_id', '=', self.survey.id)])
|
||||
self.assertEqual(len(answers), 1)
|
||||
self.assertEqual(answers.partner_id.display_name, first_partner.display_name)
|
||||
|
||||
@@ -252,7 +252,8 @@ class SurveyInvite(models.TransientModel):
|
||||
partner = False
|
||||
email_normalized = tools.email_normalize(email)
|
||||
if email_normalized:
|
||||
partner = Partner.search([('email_normalized', '=', email_normalized)])
|
||||
limit = None if self.survey_users_login_required else 1
|
||||
partner = Partner.search([('email_normalized', '=', email_normalized)], limit=limit)
|
||||
if partner:
|
||||
valid_partners |= partner
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user