Skip to content

Commit

Permalink
[MIG] mass_mailing_unique: Migration to 14.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
ivantodorovich authored and ChrisOForgeFlow committed Dec 11, 2023
1 parent 57478fa commit 8a5c52e
Show file tree
Hide file tree
Showing 27 changed files with 549 additions and 373 deletions.
36 changes: 18 additions & 18 deletions mass_mailing_unique/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Unique records for mass mailing
===============================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e10a616a0dd5c95c537e32644c23a440c452a691bc4268b3c2ea6d7d18b5f012
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,19 +17,19 @@ 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/12.0/mass_mailing_unique
:target: https://github.com/OCA/social/tree/14.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-12-0/social-12-0-mass_mailing_unique
:target: https://translation.odoo-community.org/projects/social-14-0/social-14-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/12.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/social&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of mass mailing lists to disable
duplicate entries in list names and contact emails per list.
duplicate entries in list names and contact emails.

This way you will avoid conflicts when importing contacts to a list that has a
duplicated name.
Expand All @@ -42,21 +45,15 @@ 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.
* Remove all duplicated emails in mailing contacts.

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:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mass_mailing_unique%0Aversion:%2014.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.

Expand All @@ -77,6 +74,9 @@ Contributors
* Vicent Cubells
* Pedro M. Baeza
* Ernesto Tejeda
* `Camptocamp <https://www.camptocamp.com>`_

* Iván Todorovich <[email protected]>

Maintainers
~~~~~~~~~~~
Expand All @@ -91,6 +91,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/12.0/mass_mailing_unique>`_ project on GitHub.
This module is part of the `OCA/social <https://github.com/OCA/social/tree/14.0/mass_mailing_unique>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
15 changes: 3 additions & 12 deletions mass_mailing_unique/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,11 @@
{
"name": "Unique records for mass mailing",
"summary": "Avoids duplicate mailing lists and contacts",
"version": "12.0.1.0.2",
"version": "14.0.1.0.0",
"category": "Marketing",
"website": "https://github.com/OCA/social",
"author": "Tecnativa, "
"Odoo Community Association (OCA)",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": ["mass_mailing"],
"pre_init_hook": "pre_init_hook",
"images": [
"images/error-duplicated-email.png",
"images/error-duplicated-list.png",
],
"depends": [
"mass_mailing",
],
}
46 changes: 26 additions & 20 deletions mass_mailing_unique/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,47 @@
# Copyright 2016 Tecnativa - Vicent Cubells
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).


from odoo import _
from odoo.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
If you define an 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 LOWER(c.email) AS e, l.name, COUNT(c.id)
FROM
mail_mass_mailing_contact AS c
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""")
cr.execute(
"""
SELECT email_normalized, COUNT(id) as count
FROM mailing_contact
GROUP BY email_normalized
HAVING COUNT(id) > 1
"""
)
for result in cr.fetchall():
errors.append("{0} appears {2} times in list {1}.".format(*result))

errors.append(
"There are {1} mailing contacts with the same email: {0}".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""")
cr.execute(
"""
SELECT name, COUNT(id) as count
FROM 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))

errors.append(
"There are {1} mailing lists with the same name: {0}.".format(*result)
)
# Abort if duplicates are found
if errors:
raise ValidationError(
"Fix this before installing:" + "".join("\n" + e for e in errors))
_("Unable to install module mass_mailing_unique:\n%s", "\n".join(errors))
)
48 changes: 33 additions & 15 deletions mass_mailing_unique/i18n/ca.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,54 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: mass_mailing_unique
#: sql_constraint:mail.mass_mailing.list:0
#: model:ir.model.constraint,message:mass_mailing_unique.constraint_mailing_list_unique_name
msgid "Cannot have more than one lists with the same name."
msgstr "No es pot tenir més d'una llista amb el mateix nom."

#. module: mass_mailing_unique
#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:24
#, python-format
msgid ""
"Email (%(contact_email)s) already in mailing list(s):\n"
" %(lists)s\n"
" Please use a different email address or "
"remove (%(contact_email)s) from the mailing list(s) "
"above."
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact__display_name
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list__display_name
msgid "Display Name"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact__id
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list__id
msgid "ID"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact____last_update
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list____last_update
msgid "Last Modified on"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list
#: model:ir.model,name:mass_mailing_unique.model_mailing_contact
msgid "Mailing Contact"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mailing_list
msgid "Mailing List"
msgstr "Llista d'enviament"

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_contact
msgid "Mass Mailing Contact"
msgstr "Contactes del correu massiu"
#: model:ir.model.constraint,message:mass_mailing_unique.constraint_mailing_contact_unique_email
msgid "There's already a contact with this email address"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel
msgid "Mass Mailing Subscription Information"
#: code:addons/mass_mailing_unique/hooks.py:0
#, python-format
msgid ""
"Unable to install module mass_mailing_unique:\n"
"%s"
msgstr ""

#~ msgid "Mass Mailing Contact"
#~ msgstr "Contactes del correu massiu"

#, fuzzy
#~ msgid "Cannot have the same email (%s) morethan once in the same list."
#~ msgstr ""
Expand Down
48 changes: 33 additions & 15 deletions mass_mailing_unique/i18n/de.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,54 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: mass_mailing_unique
#: sql_constraint:mail.mass_mailing.list:0
#: model:ir.model.constraint,message:mass_mailing_unique.constraint_mailing_list_unique_name
msgid "Cannot have more than one lists with the same name."
msgstr "Sie dürfen nicht mehrere Listen gleich Namens führen."

#. module: mass_mailing_unique
#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:24
#, python-format
msgid ""
"Email (%(contact_email)s) already in mailing list(s):\n"
" %(lists)s\n"
" Please use a different email address or "
"remove (%(contact_email)s) from the mailing list(s) "
"above."
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact__display_name
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list__display_name
msgid "Display Name"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact__id
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list__id
msgid "ID"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact____last_update
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list____last_update
msgid "Last Modified on"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list
#: model:ir.model,name:mass_mailing_unique.model_mailing_contact
msgid "Mailing Contact"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mailing_list
msgid "Mailing List"
msgstr "Mailingliste"

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_contact
msgid "Mass Mailing Contact"
msgstr "Massenmail-Kontakt"
#: model:ir.model.constraint,message:mass_mailing_unique.constraint_mailing_contact_unique_email
msgid "There's already a contact with this email address"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel
msgid "Mass Mailing Subscription Information"
#: code:addons/mass_mailing_unique/hooks.py:0
#, python-format
msgid ""
"Unable to install module mass_mailing_unique:\n"
"%s"
msgstr ""

#~ msgid "Mass Mailing Contact"
#~ msgstr "Massenmail-Kontakt"

#, fuzzy
#~ msgid "Cannot have the same email (%s) morethan once in the same list."
#~ msgstr ""
Expand Down
48 changes: 33 additions & 15 deletions mass_mailing_unique/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,54 @@ msgstr ""
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#. module: mass_mailing_unique
#: sql_constraint:mail.mass_mailing.list:0
#: model:ir.model.constraint,message:mass_mailing_unique.constraint_mailing_list_unique_name
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
#: code:addons/mass_mailing_unique/models/mail_mass_mailing_contact.py:24
#, python-format
msgid ""
"Email (%(contact_email)s) already in mailing list(s):\n"
" %(lists)s\n"
" Please use a different email address or "
"remove (%(contact_email)s) from the mailing list(s) "
"above."
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact__display_name
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list__display_name
msgid "Display Name"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact__id
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list__id
msgid "ID"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_contact____last_update
#: model:ir.model.fields,field_description:mass_mailing_unique.field_mailing_list____last_update
msgid "Last Modified on"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list
#: model:ir.model,name:mass_mailing_unique.model_mailing_contact
msgid "Mailing Contact"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_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"
#: model:ir.model.constraint,message:mass_mailing_unique.constraint_mailing_contact_unique_email
msgid "There's already a contact with this email address"
msgstr ""

#. module: mass_mailing_unique
#: model:ir.model,name:mass_mailing_unique.model_mail_mass_mailing_list_contact_rel
msgid "Mass Mailing Subscription Information"
#: code:addons/mass_mailing_unique/hooks.py:0
#, python-format
msgid ""
"Unable to install module mass_mailing_unique:\n"
"%s"
msgstr ""

#~ msgid "Mass Mailing Contact"
#~ msgstr "Contacto de envío masivo"

#, fuzzy
#~ msgid "Cannot have the same email (%s) morethan once in the same list."
#~ msgstr "No se puede tener el mismo email varias veces en la misma lista."
Expand Down
Loading

0 comments on commit 8a5c52e

Please sign in to comment.