diff --git a/mass_mailing_unique/README.rst b/mass_mailing_unique/README.rst index 2ba28873e8..bc326a8097 100644 --- a/mass_mailing_unique/README.rst +++ b/mass_mailing_unique/README.rst @@ -14,13 +14,13 @@ Unique records for mass mailing :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github - :target: https://github.com/OCA/social/tree/11.0/mass_mailing_unique + :target: https://github.com/OCA/social/tree/12.0/mass_mailing_unique :alt: OCA/social .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/social-11-0/social-11-0-mass_mailing_unique + :target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mass_mailing_unique :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/205/11.0 + :target: https://runbot.odoo-community.org/runbot/205/12.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -28,9 +28,8 @@ Unique records for mass mailing This module extends the functionality of mass mailing lists to disable duplicate entries in list names and contact emails per list. -This way you will avoid sending the same message more than once to the same -contact when selecting a mailing list, and you will avoid conflicts when -importing contacts to a list that has a duplicated name. +This way you will avoid conflicts when importing contacts to a list that has a +duplicated name. **Table of contents** @@ -57,7 +56,7 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -92,6 +91,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -This module is part of the `OCA/social `_ project on GitHub. +This module is part of the `OCA/social `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mass_mailing_unique/__init__.py b/mass_mailing_unique/__init__.py index 268d80e566..50800f2dd3 100644 --- a/mass_mailing_unique/__init__.py +++ b/mass_mailing_unique/__init__.py @@ -2,6 +2,5 @@ # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - from . import models from .hooks import pre_init_hook diff --git a/mass_mailing_unique/__manifest__.py b/mass_mailing_unique/__manifest__.py index beaeae84d9..b2e916e1fc 100644 --- a/mass_mailing_unique/__manifest__.py +++ b/mass_mailing_unique/__manifest__.py @@ -1,11 +1,12 @@ # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2016 Tecnativa - Vicent Cubells +# Copyright 2018 Tecnativa - Ernesto Tejeda # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Unique records for mass mailing", "summary": "Avoids duplicate mailing lists and contacts", - "version": "11.0.1.0.0", + "version": "12.0.1.0.0", "category": "Marketing", "website": "https://github.com/OCA/social", "author": "Tecnativa, " diff --git a/mass_mailing_unique/hooks.py b/mass_mailing_unique/hooks.py index 8927e114a6..6360c102ae 100644 --- a/mass_mailing_unique/hooks.py +++ b/mass_mailing_unique/hooks.py @@ -3,7 +3,6 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -from odoo import _ from odoo.exceptions import ValidationError @@ -27,8 +26,7 @@ def pre_init_hook(cr): GROUP BY l.name, e HAVING COUNT(c.id) > 1""") for result in cr.fetchall(): - errors.append( - _("{0} appears {2} times in list {1}.").format(*result)) + errors.append("{0} appears {2} times in list {1}.".format(*result)) # Search for duplicates in list's name cr.execute("""SELECT name, COUNT(id) @@ -36,11 +34,9 @@ def pre_init_hook(cr): GROUP BY name HAVING COUNT(id) > 1""") for result in cr.fetchall(): - errors.append( - _("There are {1} lists with name {0}.").format(*result)) + errors.append("There are {1} lists with name {0}.".format(*result)) # Abort if duplicates are found if errors: raise ValidationError( - _("Fix this before installing:") + - "".join("\n" + e for e in errors)) + "Fix this before installing:" + "".join("\n" + e for e in errors)) diff --git a/mass_mailing_unique/i18n/ca.po b/mass_mailing_unique/i18n/ca.po index 84d302dd90..805b14ceea 100644 --- a/mass_mailing_unique/i18n/ca.po +++ b/mass_mailing_unique/i18n/ca.po @@ -24,19 +24,13 @@ msgid "Cannot have more than one lists with the same name." msgstr "No es pot tenir més d'una llista amb el mateix nom." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "" "No es pot tenir el mateix correu electrònic més d'una vegada en la mateixa " "llista." -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Solucionar això abans d'instal·lar:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -48,13 +42,15 @@ msgid "Mass Mailing Contact" msgstr "Contactes del correu massiu" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "Hi ha {1} llistes amb el nom {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" +msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "{0} apareix {2} vegades en la llista {1}." +#~ msgid "Fix this before installing:" +#~ msgstr "Solucionar això abans d'instal·lar:" + +#~ msgid "There are {1} lists with name {0}." +#~ msgstr "Hi ha {1} llistes amb el nom {0}." + +#~ msgid "{0} appears {2} times in list {1}." +#~ msgstr "{0} apareix {2} vegades en la llista {1}." diff --git a/mass_mailing_unique/i18n/de.po b/mass_mailing_unique/i18n/de.po index 4bbb06b166..727753f8a3 100644 --- a/mass_mailing_unique/i18n/de.po +++ b/mass_mailing_unique/i18n/de.po @@ -24,18 +24,12 @@ msgid "Cannot have more than one lists with the same name." msgstr "Sie dürfen nicht mehrere Listen gleich Namens führen." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "" "Die gleiche Email-Anschrift darf nicht mehrmals in einer Liste vorkommen." -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Beheben Sie dies vor der Installation:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -47,13 +41,15 @@ msgid "Mass Mailing Contact" msgstr "Massenmail-Kontakt" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "Es gibt {1} Liste mit Name {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" +msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "{0} erscheint {2} mal in der Liste {1}." +#~ msgid "Fix this before installing:" +#~ msgstr "Beheben Sie dies vor der Installation:" + +#~ msgid "There are {1} lists with name {0}." +#~ msgstr "Es gibt {1} Liste mit Name {0}." + +#~ msgid "{0} appears {2} times in list {1}." +#~ msgstr "{0} erscheint {2} mal in der Liste {1}." diff --git a/mass_mailing_unique/i18n/es.po b/mass_mailing_unique/i18n/es.po index 076683a3ee..50fae202c1 100644 --- a/mass_mailing_unique/i18n/es.po +++ b/mass_mailing_unique/i18n/es.po @@ -24,17 +24,11 @@ msgid "Cannot have more than one lists with the same name." msgstr "No se puede tener más de una lista con el mismo nombre." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "No se puede tener el mismo email varias veces en la misma lista." -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Arregle esto antes de instalar:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -46,13 +40,15 @@ msgid "Mass Mailing Contact" msgstr "Contacto de envío masivo" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "Hay {1} listas con el nombre {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" +msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "{0} aparece {2} veces en la lista {1}." +#~ msgid "Fix this before installing:" +#~ msgstr "Arregle esto antes de instalar:" + +#~ msgid "There are {1} lists with name {0}." +#~ msgstr "Hay {1} listas con el nombre {0}." + +#~ msgid "{0} appears {2} times in list {1}." +#~ msgstr "{0} aparece {2} veces en la lista {1}." diff --git a/mass_mailing_unique/i18n/fr.po b/mass_mailing_unique/i18n/fr.po index f35a8cb7f8..2b2e8cc593 100644 --- a/mass_mailing_unique/i18n/fr.po +++ b/mass_mailing_unique/i18n/fr.po @@ -24,17 +24,11 @@ msgid "Cannot have more than one lists with the same name." msgstr "Impossible d'avoir plus d'une liste avec le même nom." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "Impossible d'avoir le même courriel plus d'une fois dans la même liste" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Fixer avant l'installation:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -46,13 +40,15 @@ msgid "Mass Mailing Contact" msgstr "Contact de la liste de diffusion" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "Il y'a {1} listes avec le nom {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" +msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "{0} Apparaît {2} fois dans la liste {1}." +#~ msgid "Fix this before installing:" +#~ msgstr "Fixer avant l'installation:" + +#~ msgid "There are {1} lists with name {0}." +#~ msgstr "Il y'a {1} listes avec le nom {0}." + +#~ msgid "{0} appears {2} times in list {1}." +#~ msgstr "{0} Apparaît {2} fois dans la liste {1}." diff --git a/mass_mailing_unique/i18n/hr.po b/mass_mailing_unique/i18n/hr.po index 70febb4423..55b666f215 100644 --- a/mass_mailing_unique/i18n/hr.po +++ b/mass_mailing_unique/i18n/hr.po @@ -26,17 +26,11 @@ msgid "Cannot have more than one lists with the same name." msgstr "Nije moguće imati više od jedne liste sa istim nazivom." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "Email mora biti jedinstven u listi." -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Ispravite sljedeće prije instalacije:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -48,13 +42,9 @@ msgid "Mass Mailing Contact" msgstr "Kontakti za masovno slanje" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "" +#~ msgid "Fix this before installing:" +#~ msgstr "Ispravite sljedeće prije instalacije:" diff --git a/mass_mailing_unique/i18n/it.po b/mass_mailing_unique/i18n/it.po index ed0bd49a56..a754ef97c0 100644 --- a/mass_mailing_unique/i18n/it.po +++ b/mass_mailing_unique/i18n/it.po @@ -24,18 +24,12 @@ msgid "Cannot have more than one lists with the same name." msgstr "Non è possibile avere più di una lista con lo stesso nome." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "" "Non è possibile inserire la stessa email più di una volta nella stessa lista." -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Da risolvere prima dell'installazione:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -47,13 +41,15 @@ msgid "Mass Mailing Contact" msgstr "Contatto Mass Mailing" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "Ci sono {1} liste con il nome {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" +msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "{0} appare {2} volte nella lista {1}." +#~ msgid "Fix this before installing:" +#~ msgstr "Da risolvere prima dell'installazione:" + +#~ msgid "There are {1} lists with name {0}." +#~ msgstr "Ci sono {1} liste con il nome {0}." + +#~ msgid "{0} appears {2} times in list {1}." +#~ msgstr "{0} appare {2} volte nella lista {1}." diff --git a/mass_mailing_unique/i18n/mass_mailing_unique.pot b/mass_mailing_unique/i18n/mass_mailing_unique.pot index 23e112040a..a4e2b5f079 100644 --- a/mass_mailing_unique/i18n/mass_mailing_unique.pot +++ b/mass_mailing_unique/i18n/mass_mailing_unique.pot @@ -4,7 +4,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 11.0\n" +"Project-Id-Version: Odoo Server 12.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: <>\n" "Language-Team: \n" @@ -19,17 +19,11 @@ msgid "Cannot have more than one lists with the same name." msgstr "" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, python-format msgid "Cannot have the same email more than once in the same list" msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -41,14 +35,7 @@ msgid "Mass Mailing Contact" msgstr "" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "" - -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" msgstr "" diff --git a/mass_mailing_unique/i18n/pt.po b/mass_mailing_unique/i18n/pt.po index cb266e4d9e..7c2fefe903 100644 --- a/mass_mailing_unique/i18n/pt.po +++ b/mass_mailing_unique/i18n/pt.po @@ -24,17 +24,11 @@ msgid "Cannot have more than one lists with the same name." msgstr "" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, python-format msgid "Cannot have the same email more than once in the same list" msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -46,13 +40,6 @@ msgid "Mass Mailing Contact" msgstr "Contacto do email em massa" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "" - -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" msgstr "" diff --git a/mass_mailing_unique/i18n/sl.po b/mass_mailing_unique/i18n/sl.po index c3326c05a6..3daf7fcd7c 100644 --- a/mass_mailing_unique/i18n/sl.po +++ b/mass_mailing_unique/i18n/sl.po @@ -25,17 +25,11 @@ msgid "Cannot have more than one lists with the same name." msgstr "Imate lahko le en seznam z istim imenom." #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/models/mass_mailing.py:21 +#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:21 #, fuzzy, python-format msgid "Cannot have the same email more than once in the same list" msgstr "Isti e-poštni naslov imate lahko le enkrat v istem seznamu." -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:45 -#, python-format -msgid "Fix this before installing:" -msgstr "Popravite pred namestitvijo:" - #. module: mass_mailing_unique #: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list msgid "Mailing List" @@ -47,13 +41,15 @@ msgid "Mass Mailing Contact" msgstr "Stik masovne pošte" #. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:40 -#, python-format -msgid "There are {1} lists with name {0}." -msgstr "{1} seznamov z imenom {0}." +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel +msgid "Mass Mailing Subscription Information" +msgstr "" -#. module: mass_mailing_unique -#: code:addons/mass_mailing_unique/hooks.py:31 -#, python-format -msgid "{0} appears {2} times in list {1}." -msgstr "{0} se pojavi {2} krat v seznamu {1}." +#~ msgid "Fix this before installing:" +#~ msgstr "Popravite pred namestitvijo:" + +#~ msgid "There are {1} lists with name {0}." +#~ msgstr "{1} seznamov z imenom {0}." + +#~ msgid "{0} appears {2} times in list {1}." +#~ msgstr "{0} se pojavi {2} krat v seznamu {1}." diff --git a/mass_mailing_unique/models/__init__.py b/mass_mailing_unique/models/__init__.py index 8251b7acfd..d795d08ae8 100644 --- a/mass_mailing_unique/models/__init__.py +++ b/mass_mailing_unique/models/__init__.py @@ -2,5 +2,7 @@ # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - +from . import mail_mass_mailing_contact +from . import mail_mass_mailing_list +from . import mail_mass_mailing_list_contact_rel from . import mass_mailing diff --git a/mass_mailing_unique/models/mail_mass_mailing_contact.py b/mass_mailing_unique/models/mail_mass_mailing_contact.py new file mode 100644 index 0000000000..3b9768affe --- /dev/null +++ b/mass_mailing_unique/models/mail_mass_mailing_contact.py @@ -0,0 +1,22 @@ +# Copyright 2018 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import _, api, models +from odoo.exceptions import ValidationError + + +class MailMassMailingContact(models.Model): + _inherit = 'mail.mass_mailing.contact' + + @api.constrains('email', 'list_ids') + def _check_email_list_ids(self): + for contact in self: + lists = contact.subscription_list_ids.mapped('list_id') + lists |= contact.list_ids + others = lists.mapped('contact_ids') - contact + + contact_email = contact.email.strip().lower() + other_emails = [e.strip().lower() for e in others.mapped('email')] + if contact_email in other_emails: + raise ValidationError(_("Cannot have the same email more " + "than once in the same list")) diff --git a/mass_mailing_unique/models/mail_mass_mailing_list.py b/mass_mailing_unique/models/mail_mass_mailing_list.py new file mode 100644 index 0000000000..9a80b8f2f4 --- /dev/null +++ b/mass_mailing_unique/models/mail_mass_mailing_list.py @@ -0,0 +1,12 @@ +# Copyright 2018 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class MailMassMailingList(models.Model): + _inherit = 'mail.mass_mailing.list' + + @api.constrains('contact_ids') + def _check_contact_ids_email(self): + self.mapped("contact_ids")._check_email_list_ids() diff --git a/mass_mailing_unique/models/mail_mass_mailing_list_contact_rel.py b/mass_mailing_unique/models/mail_mass_mailing_list_contact_rel.py new file mode 100644 index 0000000000..70cd137593 --- /dev/null +++ b/mass_mailing_unique/models/mail_mass_mailing_list_contact_rel.py @@ -0,0 +1,12 @@ +# Copyright 2018 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import api, models + + +class MailMassMailingContactListRel(models.Model): + _inherit = 'mail.mass_mailing.list_contact_rel' + + @api.constrains('contact_id', 'list_id') + def _check_contact_id_partner_id_list_id(self): + self.mapped("contact_id")._check_email_list_ids() diff --git a/mass_mailing_unique/models/mass_mailing.py b/mass_mailing_unique/models/mass_mailing.py index 849591b6cc..3ef1eaf746 100644 --- a/mass_mailing_unique/models/mass_mailing.py +++ b/mass_mailing_unique/models/mass_mailing.py @@ -2,28 +2,12 @@ # Copyright 2016 Tecnativa - Vicent Cubells # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). - -from odoo import models, api, _, tools -from odoo.exceptions import ValidationError - - -class MailMassMailingContact(models.Model): - _inherit = "mail.mass_mailing.contact" - - @api.constrains('email', 'list_ids') - def _check_email_list_ids(self): - for contact in self: - other_contact = self.search([ - ('email', '=ilike', tools.escape_psql(contact.email)), - ('id', '!=', contact.id) - ]) - if contact.list_ids & other_contact.mapped('list_ids'): - raise ValidationError(_("Cannot have the same email more " - "than once in the same list")) +from odoo import models class MailMassMailingList(models.Model): _inherit = "mail.mass_mailing.list" + _sql_constraints = [ ("unique_name", "UNIQUE(name)", "Cannot have more than one lists with the same name.") diff --git a/mass_mailing_unique/readme/DESCRIPTION.rst b/mass_mailing_unique/readme/DESCRIPTION.rst index 5e7fae79c1..1003e4e007 100644 --- a/mass_mailing_unique/readme/DESCRIPTION.rst +++ b/mass_mailing_unique/readme/DESCRIPTION.rst @@ -1,6 +1,5 @@ This module extends the functionality of mass mailing lists to disable duplicate entries in list names and contact emails per list. -This way you will avoid sending the same message more than once to the same -contact when selecting a mailing list, and you will avoid conflicts when -importing contacts to a list that has a duplicated name. +This way you will avoid conflicts when importing contacts to a list that has a +duplicated name. diff --git a/mass_mailing_unique/static/description/index.html b/mass_mailing_unique/static/description/index.html index 12f97ddaee..2d8060f410 100644 --- a/mass_mailing_unique/static/description/index.html +++ b/mass_mailing_unique/static/description/index.html @@ -3,7 +3,7 @@ - + Unique records for mass mailing