[FIX] mass_mailing: filter emails to avoid duplicates

When subscribing a user to a mailing list, the `mail.mass_mailing.contact`
created is processed to identify it's name and email from the address (method
`get_name_email` called in `add_to_list` and `name_create`).
For a better consistency, the search of existing contacts should also be done
using the method `get_name_email`.

This avoids that subscribing twice `Example <example@example.com>` fails to
detect duplicates and creates two subscriptions.

Closes #12265
This commit is contained in:
Jairo Llopis 2016-06-02 10:14:54 +02:00 committed by Martin Trigaux
parent b49818e1ee
commit 57e5d703c2
No known key found for this signature in database
GPG Key ID: 7B0E288E7C0F83A7
1 changed files with 5 additions and 1 deletions

View File

@ -65,8 +65,12 @@ class MassMailController(http.Controller):
def subscribe(self, list_id, email, **post):
cr, uid, context = request.cr, request.uid, request.context
Contacts = request.registry['mail.mass_mailing.contact']
parsed_email = Contacts.get_name_email(email, context=context)[1]
contact_ids = Contacts.search_read(cr, SUPERUSER_ID, [('list_id', '=', int(list_id)), ('email', '=', email)], ['opt_out'], context=context)
contact_ids = Contacts.search_read(
cr, SUPERUSER_ID,
[('list_id', '=', int(list_id)), ('email', '=', parsed_email)],
['opt_out'], context=context)
if not contact_ids:
Contacts.add_to_list(cr, SUPERUSER_ID, email, int(list_id), context=context)
else: