forked from OCA/social
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ADD] mass_mailing_unique: Avoid duplicates.
This new module avoids duplicates in mass mailing lists. Now you cannot have 2 lists with the same name, and you cannot have the same email repeated in a list. This will avoid sending the same mail to a contact repeated times, which will disturb him and most probably cause you to be blocked as spam.
- Loading branch information
Showing
10 changed files
with
221 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<https://github.com/OCA/social/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 | ||
<https://github.com/OCA/ | ||
social/issues/new?body=module:%20 | ||
mass_mailing_unique%0Aversion:%20 | ||
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_. | ||
|
||
Credits | ||
======= | ||
|
||
Contributors | ||
------------ | ||
|
||
* Jairo Llopis <[email protected]> | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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", | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]>\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}." |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.") | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.