diff --git a/mass_mailing_unique/README.rst b/mass_mailing_unique/README.rst new file mode 100644 index 00000000..ea59209d --- /dev/null +++ b/mass_mailing_unique/README.rst @@ -0,0 +1,67 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +=============================== +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. + +Installation +============ + +Before installing this module, you need to: + +* Remove all duplicated list names. +* Remove all duplicated emails in each list. + +Usage +===== + +To use this module, you need to try to create a duplicated mailing list, or a +duplicated email inside one. You will not can. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/205/8.0 + +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 +`_. + +Credits +======= + +Contributors +------------ + +* Jairo Llopis + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +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. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/mass_mailing_unique/__init__.py b/mass_mailing_unique/__init__.py new file mode 100644 index 00000000..baa4dd41 --- /dev/null +++ b/mass_mailing_unique/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# 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/__openerp__.py b/mass_mailing_unique/__openerp__.py new file mode 100644 index 00000000..5b7917d5 --- /dev/null +++ b/mass_mailing_unique/__openerp__.py @@ -0,0 +1,23 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# 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": "8.0.1.0.0", + "category": "Marketing", + "website": "https://grupoesoc.es", + "author": "Grupo ESOC Ingeniería de Servicios, " + "Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "pre_init_hook": "pre_init_hook", + "images": [ + "images/error-duplicated-email.png", + "images/error-duplicated-list.png", + ], + "depends": [ + "mass_mailing", + ], +} diff --git a/mass_mailing_unique/hooks.py b/mass_mailing_unique/hooks.py new file mode 100644 index 00000000..419b520f --- /dev/null +++ b/mass_mailing_unique/hooks.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import _ +from openerp.exceptions import ValidationError + + +def pre_init_hook(cr): + """Make sure there are no duplicates before installing the module. + + If you define a unique key in Odoo that cannot be applied, Odoo will log a + warning and install the module without that constraint. Since this module + is useless without those constraints, we check here if all will work before + installing, and provide a user-friendly message in case of failure. + """ + errors = list() + + # Search for duplicates in emails + cr.execute("""SELECT c.email, l.name, COUNT(c.id) + FROM + mail_mass_mailing_contact AS c + INNER JOIN mail_mass_mailing_list AS l ON c.list_id = l.id + GROUP BY l.name, l.id, c.email + HAVING COUNT(c.id) > 1""") + for result in cr.fetchall(): + errors.append( + _("{0} appears {2} times in list {1}.").format(*result)) + + # Search for duplicates in list's name + cr.execute("""SELECT name, COUNT(id) + FROM mail_mass_mailing_list + GROUP BY name + HAVING COUNT(id) > 1""") + for result in cr.fetchall(): + 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)) diff --git a/mass_mailing_unique/i18n/es.po b/mass_mailing_unique/i18n/es.po new file mode 100644 index 00000000..c2447c42 --- /dev/null +++ b/mass_mailing_unique/i18n/es.po @@ -0,0 +1,56 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mass_mailing_unique +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 8.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2016-01-29 12:37+0100\n" +"PO-Revision-Date: 2016-01-29 12:38+0100\n" +"Last-Translator: Jairo Llopis \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: \n" +"X-Generator: Poedit 1.8.5\n" + +#. module: mass_mailing_unique +#: sql_constraint:mail.mass_mailing.list:0 +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 +#: sql_constraint:mail.mass_mailing.contact:0 +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:42 +#, 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" +msgstr "Lista de correo" + +#. module: mass_mailing_unique +#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_contact +msgid "Mass Mailing Contact" +msgstr "Contacto de envío masivo" + +#. module: mass_mailing_unique +#: code:addons/mass_mailing_unique/hooks.py:37 +#, python-format +msgid "There are {1} lists with name {0}." +msgstr "Hay {1} listas con el nombre {0}." + +#. module: mass_mailing_unique +#: code:addons/mass_mailing_unique/hooks.py:28 +#, python-format +msgid "{0} appears {2} times in list {1}." +msgstr "{0} aparece {2} veces en la lista {1}." diff --git a/mass_mailing_unique/images/error-duplicated-email.png b/mass_mailing_unique/images/error-duplicated-email.png new file mode 100644 index 00000000..cb69b830 Binary files /dev/null and b/mass_mailing_unique/images/error-duplicated-email.png differ diff --git a/mass_mailing_unique/images/error-duplicated-list.png b/mass_mailing_unique/images/error-duplicated-list.png new file mode 100644 index 00000000..cb61348c Binary files /dev/null and b/mass_mailing_unique/images/error-duplicated-list.png differ diff --git a/mass_mailing_unique/models/__init__.py b/mass_mailing_unique/models/__init__.py new file mode 100644 index 00000000..81bd9a96 --- /dev/null +++ b/mass_mailing_unique/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import mass_mailing diff --git a/mass_mailing_unique/models/mass_mailing.py b/mass_mailing_unique/models/mass_mailing.py new file mode 100644 index 00000000..499671ee --- /dev/null +++ b/mass_mailing_unique/models/mass_mailing.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# © 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openerp import models + + +class MailMassMailingContact(models.Model): + _inherit = "mail.mass_mailing.contact" + _sql_constraints = [ + ("unique_mail_per_list", "UNIQUE(list_id, email)", + "Cannot have the same email more than once in the same list.") + ] + + +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/static/description/icon.png b/mass_mailing_unique/static/description/icon.png new file mode 100644 index 00000000..3a0328b5 Binary files /dev/null and b/mass_mailing_unique/static/description/icon.png differ