Browse Source

[MIG] mass_mailing_unique: Migration to 11.0

pull/294/head
ernesto 7 years ago
committed by Jairo Llopis
parent
commit
1274d12135
  1. 66
      mass_mailing_unique/README.rst
  2. 1
      mass_mailing_unique/__init__.py
  3. 5
      mass_mailing_unique/__manifest__.py
  4. 9
      mass_mailing_unique/hooks.py
  5. 1
      mass_mailing_unique/models/__init__.py
  6. 19
      mass_mailing_unique/models/mass_mailing.py
  7. 6
      mass_mailing_unique/readme/CONTRIBUTORS.rst
  8. 6
      mass_mailing_unique/readme/DESCRIPTION.rst
  9. 4
      mass_mailing_unique/readme/INSTALL.rst
  10. 2
      mass_mailing_unique/readme/USAGE.rst
  11. 1
      mass_mailing_unique/tests/__init__.py
  12. 11
      mass_mailing_unique/tests/test_mass_mailing_unique.py

66
mass_mailing_unique/README.rst

@ -1,65 +1 @@
.. 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/10.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.
Credits
=======
Contributors
------------
* Jairo Llopis <jairo.llopis@tecnativa.com>
* Vicent Cubells <vicent.cubells@tecnativa.com>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>
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 is going to be generated by oca-gen-addon-readme.**

1
mass_mailing_unique/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells # Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

5
mass_mailing_unique/__manifest__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells # Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -6,9 +5,9 @@
{ {
"name": "Unique records for mass mailing", "name": "Unique records for mass mailing",
"summary": "Avoids duplicate mailing lists and contacts", "summary": "Avoids duplicate mailing lists and contacts",
"version": "10.0.1.0.0",
"version": "11.0.1.0.0",
"category": "Marketing", "category": "Marketing",
"website": "https://tecnativa.com",
"website": "https://github.com/OCA/social",
"author": "Tecnativa, " "author": "Tecnativa, "
"Odoo Community Association (OCA)", "Odoo Community Association (OCA)",
"license": "AGPL-3", "license": "AGPL-3",

9
mass_mailing_unique/hooks.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells # Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -19,11 +18,13 @@ def pre_init_hook(cr):
errors = list() errors = list()
# Search for duplicates in emails # Search for duplicates in emails
cr.execute("""SELECT c.email, l.name, COUNT(c.id)
cr.execute("""SELECT LOWER(c.email) AS e, l.name, COUNT(c.id)
FROM FROM
mail_mass_mailing_contact AS c 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
INNER JOIN mail_mass_mailing_contact_list_rel AS cl
ON cl.contact_id = c.id
INNER JOIN mail_mass_mailing_list AS l ON cl.list_id = l.id
GROUP BY l.name, e
HAVING COUNT(c.id) > 1""") HAVING COUNT(c.id) > 1""")
for result in cr.fetchall(): for result in cr.fetchall():
errors.append( errors.append(

1
mass_mailing_unique/models/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells # Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

19
mass_mailing_unique/models/mass_mailing.py

@ -1,18 +1,25 @@
# -*- coding: utf-8 -*-
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis # Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
# Copyright 2016 Tecnativa - Vicent Cubells # Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import models
from odoo import models, api, _, tools
from odoo.exceptions import ValidationError
class MailMassMailingContact(models.Model): class MailMassMailingContact(models.Model):
_inherit = "mail.mass_mailing.contact" _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.")
]
@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"))
class MailMassMailingList(models.Model): class MailMassMailingList(models.Model):

6
mass_mailing_unique/readme/CONTRIBUTORS.rst

@ -0,0 +1,6 @@
* `Tecnativa <https://www.tecnativa.com>`_:
* Jairo Llopis
* Vicent Cubells
* Pedro M. Baeza
* Ernesto Tejeda

6
mass_mailing_unique/readme/DESCRIPTION.rst

@ -0,0 +1,6 @@
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.

4
mass_mailing_unique/readme/INSTALL.rst

@ -0,0 +1,4 @@
Before installing this module, you need to:
* Remove all duplicated list names.
* Remove all duplicated emails in each list.

2
mass_mailing_unique/readme/USAGE.rst

@ -0,0 +1,2 @@
To use this module, you need to try to create a duplicated mailing list, or a
duplicated email inside one. You will not can.

1
mass_mailing_unique/tests/__init__.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_mass_mailing_unique from . import test_mass_mailing_unique

11
mass_mailing_unique/tests/test_mass_mailing_unique.py

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Tecnativa - Pedro M. Baeza # Copyright 2016 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -17,6 +16,7 @@ class TestMassMailingUnique(common.SavepointCase):
cls.contact1 = cls.env['mail.mass_mailing.contact'].create({ cls.contact1 = cls.env['mail.mass_mailing.contact'].create({
'name': 'Contact 1', 'name': 'Contact 1',
'email': 'email1@test.com', 'email': 'email1@test.com',
'list_ids': [(6, 0, [cls.list.id])]
}) })
def test_init_hook_list(self): def test_init_hook_list(self):
@ -32,14 +32,9 @@ class TestMassMailingUnique(common.SavepointCase):
pre_init_hook(self.env.cr) pre_init_hook(self.env.cr)
def test_init_hook_contact(self): def test_init_hook_contact(self):
# Disable temporarily the constraint
self.env.cr.execute("""
ALTER TABLE mail_mass_mailing_contact
DROP CONSTRAINT mail_mass_mailing_contact_unique_mail_per_list
""")
with self.assertRaises(exceptions.ValidationError):
self.env['mail.mass_mailing.contact'].create({ self.env['mail.mass_mailing.contact'].create({
'name': 'Contact 2', 'name': 'Contact 2',
'email': 'email1@test.com', 'email': 'email1@test.com',
'list_ids': [(6, 0, [self.list.id])]
}) })
with self.assertRaises(exceptions.ValidationError):
pre_init_hook(self.env.cr)
Loading…
Cancel
Save