Browse Source

[MIG] mass_mailing_unique: Migration to 12.0

pull/317/head
ernesto 6 years ago
committed by Holger Brunn
parent
commit
879131e364
  1. 10
      mass_mailing_unique/README.rst
  2. 1
      mass_mailing_unique/__init__.py
  3. 3
      mass_mailing_unique/__manifest__.py
  4. 10
      mass_mailing_unique/hooks.py
  5. 4
      mass_mailing_unique/models/__init__.py
  6. 22
      mass_mailing_unique/models/mail_mass_mailing_contact.py
  7. 12
      mass_mailing_unique/models/mail_mass_mailing_list.py
  8. 12
      mass_mailing_unique/models/mail_mass_mailing_list_contact_rel.py
  9. 20
      mass_mailing_unique/models/mass_mailing.py
  10. 5
      mass_mailing_unique/readme/DESCRIPTION.rst
  11. 6
      mass_mailing_unique/static/description/index.html
  12. 0
      mass_mailing_unique/static/img/error-duplicated-email.png
  13. 0
      mass_mailing_unique/static/img/error-duplicated-list.png
  14. 49
      mass_mailing_unique/tests/test_mass_mailing_unique.py

10
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|
@ -57,7 +57,7 @@ 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:%20mass_mailing_unique%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_unique%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues.
@ -92,6 +92,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 <https://github.com/OCA/social/tree/11.0/mass_mailing_unique>`_ project on GitHub.
This module is part of the `OCA/social <https://github.com/OCA/social/tree/12.0/mass_mailing_unique>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

1
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

3
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, "

10
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))

4
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

22
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"))

12
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()

12
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()

20
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.")

5
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.

6
mass_mailing_unique/static/description/index.html

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/11.0/mass_mailing_unique"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-11-0/social-11-0-mass_mailing_unique"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/11.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/social/tree/12.0/mass_mailing_unique"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/social-12-0/social-12-0-mass_mailing_unique"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/205/12.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>This module extends the functionality of mass mailing lists to disable
duplicate entries in list names and contact emails per list.</p>
<p>This way you will avoid sending the same message more than once to the same
@ -405,7 +405,7 @@ duplicated email inside one. You will not can.</p>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/social/issues">GitHub Issues</a>.
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
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_unique%0Aversion:%2011.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_unique%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
@ -435,7 +435,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>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.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/11.0/mass_mailing_unique">OCA/social</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/12.0/mass_mailing_unique">OCA/social</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>

0
mass_mailing_unique/images/error-duplicated-email.png → mass_mailing_unique/static/img/error-duplicated-email.png

Before

Width: 937  |  Height: 289  |  Size: 41 KiB

After

Width: 937  |  Height: 289  |  Size: 41 KiB

0
mass_mailing_unique/images/error-duplicated-list.png → mass_mailing_unique/static/img/error-duplicated-list.png

Before

Width: 961  |  Height: 313  |  Size: 36 KiB

After

Width: 961  |  Height: 313  |  Size: 36 KiB

49
mass_mailing_unique/tests/test_mass_mailing_unique.py

@ -3,6 +3,7 @@
from odoo.tests import common
from odoo import exceptions
from ..hooks import pre_init_hook
@ -31,10 +32,56 @@ class TestMassMailingUnique(common.SavepointCase):
with self.assertRaises(exceptions.ValidationError):
pre_init_hook(self.env.cr)
def test_init_hook_contact(self):
def test_add_contact_with_list(self):
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])]
})
def test_add_contact_with_subscription(self):
with self.assertRaises(exceptions.ValidationError):
self.env['mail.mass_mailing.contact'].create({
'name': 'Contact 2',
'email': 'email1@test.com',
'subscription_list_ids': [
(0, 0, {'list_id': self.list.id})
]
})
def test_add_list_with_contacts(self):
contact2 = self.env['mail.mass_mailing.contact'].create({
'name': 'Contact 2',
'email': 'email1@test.com',
})
with self.assertRaises(exceptions.ValidationError):
self.env['mail.mass_mailing.list'].create({
'name': 'Test list 2',
'contact_ids': [(6, 0, (self.contact1 | contact2).ids)]
})
def test_add_list_with_subscriptions(self):
contact2 = self.env['mail.mass_mailing.contact'].create({
'name': 'Contact 2',
'email': 'email1@test.com',
})
with self.assertRaises(exceptions.ValidationError):
self.env['mail.mass_mailing.list'].create({
'name': 'Test list 2',
'subscription_contact_ids': [
(0, 0, {'contact_id': self.contact1.id}),
(0, 0, {'contact_id': contact2.id})
]
})
def test_add_list_contact_rel(self):
contact2 = self.env['mail.mass_mailing.contact'].create({
'name': 'Contact 2',
'email': 'email1@test.com',
})
with self.assertRaises(exceptions.ValidationError):
self.env['mail.mass_mailing.list_contact_rel'].create({
'list_id': self.list.id,
'contact_id': contact2.id
})
Loading…
Cancel
Save