mirror of https://github.com/OCA/social.git
[MIG] mass_mailing_unique: Migration to 11.0
parent
c39544a2db
commit
1274d12135
|
@ -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,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
@ -6,9 +5,9 @@
|
|||
{
|
||||
"name": "Unique records for mass mailing",
|
||||
"summary": "Avoids duplicate mailing lists and contacts",
|
||||
"version": "10.0.1.0.0",
|
||||
"version": "11.0.1.0.0",
|
||||
"category": "Marketing",
|
||||
"website": "https://tecnativa.com",
|
||||
"website": "https://github.com/OCA/social",
|
||||
"author": "Tecnativa, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"license": "AGPL-3",
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
@ -19,11 +18,13 @@ def pre_init_hook(cr):
|
|||
errors = list()
|
||||
|
||||
# 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
|
||||
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""")
|
||||
for result in cr.fetchall():
|
||||
errors.append(
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
|
|
@ -1,18 +1,25 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2015 Grupo ESOC Ingeniería de Servicios, S.L.U. - Jairo Llopis
|
||||
# Copyright 2016 Tecnativa - Vicent Cubells
|
||||
# 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):
|
||||
_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):
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
* `Tecnativa <https://www.tecnativa.com>`_:
|
||||
|
||||
* Jairo Llopis
|
||||
* Vicent Cubells
|
||||
* Pedro M. Baeza
|
||||
* Ernesto Tejeda
|
|
@ -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.
|
|
@ -0,0 +1,4 @@
|
|||
Before installing this module, you need to:
|
||||
|
||||
* Remove all duplicated list names.
|
||||
* Remove all duplicated emails in each list.
|
|
@ -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,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from . import test_mass_mailing_unique
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Copyright 2016 Tecnativa - Pedro M. Baeza
|
||||
# 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({
|
||||
'name': 'Contact 1',
|
||||
'email': 'email1@test.com',
|
||||
'list_ids': [(6, 0, [cls.list.id])]
|
||||
})
|
||||
|
||||
def test_init_hook_list(self):
|
||||
|
@ -32,14 +32,9 @@ class TestMassMailingUnique(common.SavepointCase):
|
|||
pre_init_hook(self.env.cr)
|
||||
|
||||
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({
|
||||
'name': 'Contact 2',
|
||||
'email': 'email1@test.com',
|
||||
'list_ids': [(6, 0, [self.list.id])]
|
||||
})
|
||||
with self.assertRaises(exceptions.ValidationError):
|
||||
pre_init_hook(self.env.cr)
|
||||
|
|
Loading…
Reference in New Issue