diff --git a/base_import_mail_disable/README.rst b/base_import_mail_disable/README.rst new file mode 100644 index 00000000000..3727a382e3f --- /dev/null +++ b/base_import_mail_disable/README.rst @@ -0,0 +1,112 @@ +======================== +Base Import Mail Disable +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:3d3dc34640e4bb2b9924e591cdcbd656dcfadc8cc0844ad76932fff6aab1b40c + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fserver--tools-lightgray.png?logo=github + :target: https://github.com/OCA/server-tools/tree/18.0/base_import_mail_disable + :alt: OCA/server-tools +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/server-tools-18-0/server-tools-18-0-base_import_mail_disable + :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/server-tools&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module ensures that Odoo strictly disables outbound emails when +importing massive quantities of data via the standard ``base_import`` +wizard. + +**Problems it solves:** + +- Safeguards the external SMTP queue against badly-coded or third-party + custom modules that might explicitly trigger ``mail.mail.create`` or + ``template.send_mail()`` hooks during bulk imports. +- Dynamically intercepts outbound mail in the background and silently + cancels the transmission sequence natively, guaranteeing 100% SMTP + silence during data migrations. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To verify the functionality of the module: + +1. Go to any list view in Odoo (e.g., *Contacts*, *Sales Orders*, + *Users*). +2. Click **Favorites > Import records**. +3. Upload your CSV/Excel file normally. +4. The module operates entirely in the background. It will automatically + intercept the ``model.load()`` operation globally. All explicitly + triggered outbound emails will be routed to the outgoing queue + gracefully as "Cancelled," meaning zero notifications will reach + end-user inboxes. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub 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 `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Heliconia Solutions Pvt. Ltd. + +Contributors +------------ + +- `Heliconia Solutions Pvt. Ltd. `__ + + - Bhavesh Heliconia + +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-Bhavesh Heliconia| image:: https://github.com/Bhavesh Heliconia.png?size=40px + :target: https://github.com/Bhavesh Heliconia + :alt: Bhavesh Heliconia + +Current `maintainer `__: + +|maintainer-Bhavesh Heliconia| + +This module is part of the `OCA/server-tools `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_import_mail_disable/__init__.py b/base_import_mail_disable/__init__.py new file mode 100644 index 00000000000..39b73f082b8 --- /dev/null +++ b/base_import_mail_disable/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import models diff --git a/base_import_mail_disable/__manifest__.py b/base_import_mail_disable/__manifest__.py new file mode 100644 index 00000000000..d2d41e4fe85 --- /dev/null +++ b/base_import_mail_disable/__manifest__.py @@ -0,0 +1,22 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Base Import Mail Disable", + "summary": "Disables sending of emails and notifications during data imports " + "to avoid flooding", + "version": "18.0.1.0.0", + "category": "Tools", + "website": "https://github.com/OCA/server-tools", + "author": "Heliconia Solutions Pvt. Ltd., Odoo Community Association (OCA)", + "license": "AGPL-3", + "depends": [ + "base_import", + "mail", + ], + "data": [], + "maintainers": ["Bhavesh Heliconia"], + "installable": True, + "application": False, + "auto_install": False, +} diff --git a/base_import_mail_disable/models/__init__.py b/base_import_mail_disable/models/__init__.py new file mode 100644 index 00000000000..74c4a16ef19 --- /dev/null +++ b/base_import_mail_disable/models/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import mail_mail diff --git a/base_import_mail_disable/models/mail_mail.py b/base_import_mail_disable/models/mail_mail.py new file mode 100644 index 00000000000..152f76a07a3 --- /dev/null +++ b/base_import_mail_disable/models/mail_mail.py @@ -0,0 +1,35 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class MailMail(models.Model): + _inherit = "mail.mail" + + @api.model_create_multi + def create(self, values_list): + """ + Intercept hard-coded mail.mail record creations during mass imports. + Instead of letting them queue normally, forcefully flag them as 'cancel' + so the mail cron job inherently ignores them. + """ + if self.env.context.get("import_file"): + for vals in values_list: + vals["state"] = "cancel" + vals["auto_delete"] = False + return super().create(values_list) + + def send(self, auto_commit=False, raise_exception=False, post_send_callback=None): + """ + Intercept synchronous/immediate mail dispatch calls during mass imports. + Simulate a successful dispatch by returning True, while protecting the + SMTP server from spam. + """ + if self.env.context.get("import_file"): + return True + return super().send( + auto_commit=auto_commit, + raise_exception=raise_exception, + post_send_callback=post_send_callback, + ) diff --git a/base_import_mail_disable/pyproject.toml b/base_import_mail_disable/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/base_import_mail_disable/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/base_import_mail_disable/readme/CONTRIBUTORS.md b/base_import_mail_disable/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..2f6060845e2 --- /dev/null +++ b/base_import_mail_disable/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Heliconia Solutions Pvt. Ltd.](https://www.heliconia.io) + - Bhavesh Heliconia diff --git a/base_import_mail_disable/readme/DESCRIPTION.md b/base_import_mail_disable/readme/DESCRIPTION.md new file mode 100644 index 00000000000..573f9a68b91 --- /dev/null +++ b/base_import_mail_disable/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module ensures that Odoo strictly disables outbound emails when importing massive quantities of data via the standard `base_import` wizard. + +**Problems it solves:** +* Safeguards the external SMTP queue against badly-coded or third-party custom modules that might explicitly trigger `mail.mail.create` or `template.send_mail()` hooks during bulk imports. +* Dynamically intercepts outbound mail in the background and silently cancels the transmission sequence natively, guaranteeing 100% SMTP silence during data migrations. diff --git a/base_import_mail_disable/readme/USAGE.md b/base_import_mail_disable/readme/USAGE.md new file mode 100644 index 00000000000..1ff03902e3a --- /dev/null +++ b/base_import_mail_disable/readme/USAGE.md @@ -0,0 +1,6 @@ +To verify the functionality of the module: + +1. Go to any list view in Odoo (e.g., *Contacts*, *Sales Orders*, *Users*). +2. Click **Favorites > Import records**. +3. Upload your CSV/Excel file normally. +4. The module operates entirely in the background. It will automatically intercept the `model.load()` operation globally. All explicitly triggered outbound emails will be routed to the outgoing queue gracefully as "Cancelled," meaning zero notifications will reach end-user inboxes. diff --git a/base_import_mail_disable/static/description/icon.png b/base_import_mail_disable/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/base_import_mail_disable/static/description/icon.png differ diff --git a/base_import_mail_disable/static/description/index.html b/base_import_mail_disable/static/description/index.html new file mode 100644 index 00000000000..348c9cd6e0c --- /dev/null +++ b/base_import_mail_disable/static/description/index.html @@ -0,0 +1,455 @@ + + + + + +Base Import Mail Disable + + + +
+

Base Import Mail Disable

+ + +

Beta License: AGPL-3 OCA/server-tools Translate me on Weblate Try me on Runboat

+

This module ensures that Odoo strictly disables outbound emails when +importing massive quantities of data via the standard base_import +wizard.

+

Problems it solves:

+
    +
  • Safeguards the external SMTP queue against badly-coded or third-party +custom modules that might explicitly trigger mail.mail.create or +template.send_mail() hooks during bulk imports.
  • +
  • Dynamically intercepts outbound mail in the background and silently +cancels the transmission sequence natively, guaranteeing 100% SMTP +silence during data migrations.
  • +
+

Table of contents

+ +
+

Usage

+

To verify the functionality of the module:

+
    +
  1. Go to any list view in Odoo (e.g., Contacts, Sales Orders, +Users).
  2. +
  3. Click Favorites > Import records.
  4. +
  5. Upload your CSV/Excel file normally.
  6. +
  7. The module operates entirely in the background. It will automatically +intercept the model.load() operation globally. All explicitly +triggered outbound emails will be routed to the outgoing queue +gracefully as “Cancelled,” meaning zero notifications will reach +end-user inboxes.
  8. +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub 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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Heliconia Solutions Pvt. Ltd.
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

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.

+

Current maintainer:

+

Bhavesh Heliconia

+

This module is part of the OCA/server-tools project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/base_import_mail_disable/tests/__init__.py b/base_import_mail_disable/tests/__init__.py new file mode 100644 index 00000000000..b04a15013bb --- /dev/null +++ b/base_import_mail_disable/tests/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import test_base_import_mail_disable diff --git a/base_import_mail_disable/tests/test_base_import_mail_disable.py b/base_import_mail_disable/tests/test_base_import_mail_disable.py new file mode 100644 index 00000000000..52b995009de --- /dev/null +++ b/base_import_mail_disable/tests/test_base_import_mail_disable.py @@ -0,0 +1,60 @@ +# Copyright 2026 Heliconia Solutions Pvt. Ltd. +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.addons.base.tests.common import BaseCommon + + +class TestBaseImportMailDisable(BaseCommon): + def test_explicit_mail_handling(self): + """Test the three edge cases explicitly covered by our mail.mail override.""" + self.partner.email = "silence@test.imports.invalid" + template = self.env["mail.template"].create( + { + "name": "Dummy Template", + "model_id": self.env["ir.model"] + .search([("model", "=", "res.partner")], limit=1) + .id, + "body_html": "

Test

", + "subject": "Dummy Subject", + } + ) + import_env = self.env(context=dict(self.env.context, import_file=True)) + + # Case 1: message_post explicit call forcing a mail out + import_env["res.partner"].browse(self.partner.id).message_post( + body="Forced email", + message_type="email", + subtype_xmlid="mail.mt_comment", + partner_ids=[self.partner.id], + ) + + # Case 2: mail.template explicit send + import_env["mail.template"].browse(template.id).send_mail( + self.partner.id, force_send=True + ) + + # Case 3: mail.mail raw creation + mail = import_env["mail.mail"].create( + { + "subject": "Force Raw Mail Send", + "body_html": "

Raw mail

", + "email_to": self.partner.email, + } + ) + mail.send() + spam_mails = self.env["mail.mail"].search( + [("email_to", "=", self.partner.email)] + ) + + self.assertTrue( + len(spam_mails) >= 1, + "The mail records should have been technically generated by the " + "explicit calls", + ) + for spam_mail in spam_mails: + self.assertEqual( + spam_mail.state, + "cancel", + "The outgoing mail must be intercepted and permanently flagged " + "as cancelled.", + )