Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 103 additions & 0 deletions website_mass_mailing_no_duplicate/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
======================================
Website - Mass Mailing - No duplicates
======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:158e89f61f2770f93ad3c67969c8e4726a8e73cc45e4225c218e405d0ca602a4
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fwebsite-lightgray.png?logo=github
:target: https://github.com/OCA/website/tree/18.0/website_mass_mailing_no_duplicate
:alt: OCA/website
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/website-18-0/website-18-0-website_mass_mailing_no_duplicate
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/website&target_branch=18.0
:alt: Try me on Runboat

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

This module extends the ``website`` and ``mass_mailing`` Odoo modules to
prevent duplicates entries in ``mailing.contact`` tables.

**Rational**

In Odoo website, if the page contains Customer Form type = 'Subscribe to
one (or many) newsletters', the form creates a new mailing.contact. That
can generate annoying duplicates.

This module prevent such duplicated entries, updating existing
mailing.contact, if exists.

**Table of contents**

.. contents::
:local:

Known issues / Roadmap
======================

This module is a bugfix. When we use the other widget "Newsletters"
(that is more simple), the widget doesn't create duplicates.

To Do: check if this module is still necessary in more recent version of
Odoo.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/website/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/website/issues/new?body=module:%20website_mass_mailing_no_duplicate%0Aversion:%2018.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.

Credits
=======

Authors
-------

* GRAP

Contributors
------------

- Sylvain LE GAL

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px
:target: https://github.com/legalsylvain
:alt: legalsylvain

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-legalsylvain|

This module is part of the `OCA/website <https://github.com/OCA/website/tree/18.0/website_mass_mailing_no_duplicate>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions website_mass_mailing_no_duplicate/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import controllers
14 changes: 14 additions & 0 deletions website_mass_mailing_no_duplicate/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2026 - Today: GRAP https://www.grap.coop
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
{
"name": "Website - Mass Mailing - No duplicates",
"summary": "Prevent duplicate of mailing contacts"
" when contact subscribes on the website",
"version": "18.0.1.0.0",
"author": "GRAP, Odoo Community Association (OCA)",
"maintainers": ["legalsylvain"],
"website": "https://github.com/OCA/website",
"license": "AGPL-3",
"category": "Website",
"depends": ["website_mass_mailing"],
}
1 change: 1 addition & 0 deletions website_mass_mailing_no_duplicate/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import form
12 changes: 12 additions & 0 deletions website_mass_mailing_no_duplicate/controllers/form.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from odoo.tools.misc import clean_context

from odoo.addons.website.controllers import form


class WebsiteForm(form.WebsiteForm):
def insert_record(self, request, model, values, custom, meta=None):
if model.model == "mailing.contact":
request.update_context(
**clean_context({"mailing_contact_from_website": True})
)
return super().insert_record(request, model, values, custom, meta=meta)
Empty file.
1 change: 1 addition & 0 deletions website_mass_mailing_no_duplicate/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mailing_contact
49 changes: 49 additions & 0 deletions website_mass_mailing_no_duplicate/models/mailing_contact.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2026 - Today: GRAP https://www.grap.coop
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
import logging

from odoo import api, models, tools
from odoo.fields import Command

_logger = logging.getLogger(__name__)


class MailingContact(models.Model):
_inherit = "mailing.contact"

@api.model_create_multi
def create(self, vals_list):
if not self.env.context.get("mailing_contact_from_website", False):
return super().create(vals_list)
new_vals_list = []
all_existing_contacts = self
for vals in vals_list:
existing_contacts = self.search(
[("email_normalized", "=", tools.email_normalize(vals.get("email")))]
)
if existing_contacts:
new_list_ids = vals.get("list_ids")[0][2]
existing_list_ids = existing_contacts.mapped("list_ids").ids
to_add_list_ids = list(set(new_list_ids) - set(existing_list_ids))
all_existing_contacts |= existing_contacts[0]
if to_add_list_ids:
_logger.info(
f"mailing.contact #{existing_contacts[0].id}:"
f" Adding new mailing list {to_add_list_ids}."
)
existing_contacts[0].write(
{
"list_ids": [
(Command.link(list_id)) for list_id in to_add_list_ids
]
}
)
else:
_logger.info(
f"mailing.contact #{existing_contacts[0].id}:"
" No mailing list to change."
)
else:
new_vals_list.append(vals)

return super().create(new_vals_list) | all_existing_contacts
3 changes: 3 additions & 0 deletions website_mass_mailing_no_duplicate/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions website_mass_mailing_no_duplicate/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Sylvain LE GAL
9 changes: 9 additions & 0 deletions website_mass_mailing_no_duplicate/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This module extends the ``website`` and ``mass_mailing`` Odoo modules to prevent
duplicates entries in ``mailing.contact`` tables.

**Rational**

In Odoo website, if the page contains Customer Form type = 'Subscribe to one (or many) newsletters', the form creates a new mailing.contact.
That can generate annoying duplicates.

This module prevent such duplicated entries, updating existing mailing.contact, if exists.
5 changes: 5 additions & 0 deletions website_mass_mailing_no_duplicate/readme/ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
This module is a bugfix. When we use the other widget "Newsletters"
(that is more simple), the widget doesn't create duplicates.

To Do: check if this module is still necessary in more recent
version of Odoo.
Loading
Loading