Browse Source

Follow guidelines in hooks, remove redundant credits.

pull/38/head
Jairo Llopis 9 years ago
parent
commit
92c087e9d9
  1. 5
      mass_mailing_unique/README.rst
  2. 40
      mass_mailing_unique/__init__.py
  3. 2
      mass_mailing_unique/__openerp__.py
  4. 43
      mass_mailing_unique/hooks.py

5
mass_mailing_unique/README.rst

@ -46,11 +46,6 @@ mass_mailing_unique%0Aversion:%20
Credits
=======
Images
------
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.
Contributors
------------

40
mass_mailing_unique/__init__.py

@ -2,43 +2,5 @@
# © 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
from . import models
def require_no_duplicates(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 AS list, COUNT(c.id) AS duplicates
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.dictfetchall():
errors.append(
_("%(email)s appears %(duplicates)d times in list %(list)s") %
result)
# Search for duplicates in list's name
cr.execute("""SELECT name, COUNT(id) as duplicates
FROM mail_mass_mailing_list
GROUP BY name
HAVING COUNT(id) > 1""")
for result in cr.dictfetchall():
errors.append(
_("there are %(duplicates)d lists with name %(name)s") % result)
# Abort if duplicates are found
if errors:
raise ValidationError(
_("Fix this before installing: %s.") % ", ".join(errors))
from .hooks import pre_init_hook

2
mass_mailing_unique/__openerp__.py

@ -12,7 +12,7 @@
"license": "AGPL-3",
"application": False,
"installable": True,
"pre_init_hook": "require_no_duplicates",
"pre_init_hook": "pre_init_hook",
"images": [
"images/error-duplicated-email.png",
"images/error-duplicated-list.png",

43
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 AS list, COUNT(c.id) AS duplicates
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.dictfetchall():
errors.append(
_("%(email)s appears %(duplicates)d times in list %(list)s") %
result)
# Search for duplicates in list's name
cr.execute("""SELECT name, COUNT(id) as duplicates
FROM mail_mass_mailing_list
GROUP BY name
HAVING COUNT(id) > 1""")
for result in cr.dictfetchall():
errors.append(
_("there are %(duplicates)d lists with name %(name)s") % result)
# Abort if duplicates are found
if errors:
raise ValidationError(
_("Fix this before installing: %s.") % ", ".join(errors))
Loading…
Cancel
Save