diff --git a/mail_force_email_notification/README.rst b/mail_force_email_notification/README.rst new file mode 100644 index 000000000..4ca2ea120 --- /dev/null +++ b/mail_force_email_notification/README.rst @@ -0,0 +1,134 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +============================= +Mail Force Email Notification +============================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:bc735d617f6e55d39427e192b0b118b534714ab642d16ffc1e71aa6e19394f8d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/19.0/mail_force_email_notification + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-19-0/mail-19-0-mail_force_email_notification + :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/mail&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of Odoo's mail notification system +to allow forcing email notifications through context keys. By default, +Odoo sends internal notifications to connected users and email +notifications to external partners or disconnected users. + +With this module, you can override this behavior by setting the +``force_notification_by_email`` context key, ensuring specific +notifications are always sent by email regardless of the user's +connection status or notification preferences. This is particularly +useful when you need to maintain an email trail for certain +communications or ensure critical notifications are delivered via email. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +1. For developers implementing the feature: + + - Add the context key ``force_notification_by_email=True`` when + sending messages through the mail thread + + .. code:: python + + self.env['mail.thread'].with_context( + force_notification_by_email=True + ).message_post( + body="Your message", + partner_ids=[partner.id], + ) + +2. For end users: + + - No specific configuration is needed + - When developers have implemented the feature in specific actions: + + - Messages will be sent by email regardless of your notification + preferences + - You will receive email notifications even if you are connected to + Odoo + - Your notification preferences in your user settings won't affect + these specific notifications + +**Example Use Cases:** + +- Critical notifications that need email documentation +- Automated workflows where email trail is required +- Compliance requirements where email proof of communication is + necessary + +**Note:** This module only affects notifications where the context key +has been specifically implemented. All other notifications will follow +standard Odoo behavior. + +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 +------- + +* Camptocamp + +Contributors +------------ + +- `Camptocamp `__ + + - Rafael Lima + +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. + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_force_email_notification/__init__.py b/mail_force_email_notification/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mail_force_email_notification/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_force_email_notification/__manifest__.py b/mail_force_email_notification/__manifest__.py new file mode 100644 index 000000000..696e6edce --- /dev/null +++ b/mail_force_email_notification/__manifest__.py @@ -0,0 +1,15 @@ +# Copyright 2025 Camptocamp (http://www.camptocamp.com). +# @author Rafael Lima +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "Mail Force Email Notification", + "summary": "Context key to define notifications to be sent by email" + "defined by force_notification_by_email context key", + "version": "19.0.1.0.0", + "author": "Camptocamp, Odoo Community Association (OCA)", + "license": "AGPL-3", + "category": "Hidden", + "depends": ["mail"], + "website": "https://github.com/OCA/mail", +} diff --git a/mail_force_email_notification/i18n/it.po b/mail_force_email_notification/i18n/it.po new file mode 100644 index 000000000..43786aa1c --- /dev/null +++ b/mail_force_email_notification/i18n/it.po @@ -0,0 +1,22 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_force_email_notification +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2025-04-05 11:06+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.10.2\n" + +#. module: mail_force_email_notification +#: model:ir.model,name:mail_force_email_notification.model_mail_thread +msgid "Email Thread" +msgstr "Discussione e-mail" diff --git a/mail_force_email_notification/i18n/mail_force_email_notification.pot b/mail_force_email_notification/i18n/mail_force_email_notification.pot new file mode 100644 index 000000000..0aad777cb --- /dev/null +++ b/mail_force_email_notification/i18n/mail_force_email_notification.pot @@ -0,0 +1,19 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_force_email_notification +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_force_email_notification +#: model:ir.model,name:mail_force_email_notification.model_mail_thread +msgid "Email Thread" +msgstr "" diff --git a/mail_force_email_notification/models/__init__.py b/mail_force_email_notification/models/__init__.py new file mode 100644 index 000000000..b70a9f2d0 --- /dev/null +++ b/mail_force_email_notification/models/__init__.py @@ -0,0 +1 @@ +from . import mail_thread diff --git a/mail_force_email_notification/models/mail_thread.py b/mail_force_email_notification/models/mail_thread.py new file mode 100644 index 000000000..bf0ea0f9c --- /dev/null +++ b/mail_force_email_notification/models/mail_thread.py @@ -0,0 +1,18 @@ +# Copyright 2025 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) + +from odoo import models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + def _notify_get_recipients(self, message, msg_vals, **kwargs): + recipients = super()._notify_get_recipients(message, msg_vals, **kwargs) + # The context key `force_notification_by_email` allows to + # push notifications through email even if the user has his preferences + # configured to use Odoo. + if self.env.context.get("force_notification_by_email"): + for partner in recipients: + partner["notif"] = "email" + return recipients diff --git a/mail_force_email_notification/pyproject.toml b/mail_force_email_notification/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_force_email_notification/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_force_email_notification/readme/CONTRIBUTORS.md b/mail_force_email_notification/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..926246237 --- /dev/null +++ b/mail_force_email_notification/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- [Camptocamp](https://www.camptocamp.com) + + > - Rafael Lima \ diff --git a/mail_force_email_notification/readme/DESCRIPTION.md b/mail_force_email_notification/readme/DESCRIPTION.md new file mode 100644 index 000000000..f22d33fb6 --- /dev/null +++ b/mail_force_email_notification/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module extends the functionality of Odoo's mail notification system to allow forcing email notifications through context keys. By default, Odoo sends internal notifications to connected users and email notifications to external partners or disconnected users. + +With this module, you can override this behavior by setting the `force_notification_by_email` context key, ensuring specific notifications are always sent by email regardless of the user's connection status or notification preferences. This is particularly useful when you need to maintain an email trail for certain communications or ensure critical notifications are delivered via email. \ No newline at end of file diff --git a/mail_force_email_notification/readme/USAGE.md b/mail_force_email_notification/readme/USAGE.md new file mode 100644 index 000000000..6ae5febd4 --- /dev/null +++ b/mail_force_email_notification/readme/USAGE.md @@ -0,0 +1,27 @@ +To use this module, you need to: + +1. For developers implementing the feature: + - Add the context key `force_notification_by_email=True` when sending messages through the mail thread + ```python + self.env['mail.thread'].with_context( + force_notification_by_email=True + ).message_post( + body="Your message", + partner_ids=[partner.id], + ) + ``` + +2. For end users: + - No specific configuration is needed + - When developers have implemented the feature in specific actions: + - Messages will be sent by email regardless of your notification preferences + - You will receive email notifications even if you are connected to Odoo + - Your notification preferences in your user settings won't affect these specific notifications + +**Example Use Cases:** + +- Critical notifications that need email documentation +- Automated workflows where email trail is required +- Compliance requirements where email proof of communication is necessary + +**Note:** This module only affects notifications where the context key has been specifically implemented. All other notifications will follow standard Odoo behavior. \ No newline at end of file diff --git a/mail_force_email_notification/readme/newsfragments/.gitkeep b/mail_force_email_notification/readme/newsfragments/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/mail_force_email_notification/static/description/icon.png b/mail_force_email_notification/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/mail_force_email_notification/static/description/icon.png differ diff --git a/mail_force_email_notification/static/description/index.html b/mail_force_email_notification/static/description/index.html new file mode 100644 index 000000000..9a66a6204 --- /dev/null +++ b/mail_force_email_notification/static/description/index.html @@ -0,0 +1,489 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mail Force Email Notification

+ +

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

+

This module extends the functionality of Odoo’s mail notification system +to allow forcing email notifications through context keys. By default, +Odoo sends internal notifications to connected users and email +notifications to external partners or disconnected users.

+

With this module, you can override this behavior by setting the +force_notification_by_email context key, ensuring specific +notifications are always sent by email regardless of the user’s +connection status or notification preferences. This is particularly +useful when you need to maintain an email trail for certain +communications or ensure critical notifications are delivered via email.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  1. For developers implementing the feature:

    +
      +
    • Add the context key force_notification_by_email=True when +sending messages through the mail thread
    • +
    +
    +self.env['mail.thread'].with_context(
    +    force_notification_by_email=True
    +).message_post(
    +    body="Your message",
    +    partner_ids=[partner.id],
    +)
    +
    +
  2. +
  3. For end users:

    +
      +
    • No specific configuration is needed
    • +
    • When developers have implemented the feature in specific actions:
        +
      • Messages will be sent by email regardless of your notification +preferences
      • +
      • You will receive email notifications even if you are connected to +Odoo
      • +
      • Your notification preferences in your user settings won’t affect +these specific notifications
      • +
      +
    • +
    +
  4. +
+

Example Use Cases:

+
    +
  • Critical notifications that need email documentation
  • +
  • Automated workflows where email trail is required
  • +
  • Compliance requirements where email proof of communication is +necessary
  • +
+

Note: This module only affects notifications where the context key +has been specifically implemented. All other notifications will follow +standard Odoo behavior.

+
+
+

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

+
    +
  • Camptocamp
  • +
+
+
+

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.

+

This module is part of the OCA/mail project on GitHub.

+

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

+
+
+
+
+ + diff --git a/mail_force_email_notification/tests/__init__.py b/mail_force_email_notification/tests/__init__.py new file mode 100644 index 000000000..d10f37dba --- /dev/null +++ b/mail_force_email_notification/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_thread diff --git a/mail_force_email_notification/tests/test_mail_thread.py b/mail_force_email_notification/tests/test_mail_thread.py new file mode 100644 index 000000000..b38eb727e --- /dev/null +++ b/mail_force_email_notification/tests/test_mail_thread.py @@ -0,0 +1,55 @@ +# Copyright 2025 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import tagged +from odoo.tests.common import TransactionCase + + +@tagged("-at_install", "post_install") +class TestMailThread(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.env = cls.env(context=dict(cls.env.context, tracking_disable=True)) + cls.user = cls.env["res.users"].create( + { + "name": "Mark Test", + "login": "test", + "notification_type": "inbox", + } + ) + cls.partner = cls.user.partner_id + + def test_force_email_notification(self): + """Test that notifications are sent by email when forced""" + message = self.env["mail.message"].create( + { + "body": "Test message", + "model": "res.partner", + "res_id": self.partner.id, + } + ) + # Test without forcing email + recipients = self.env["mail.thread"]._notify_get_recipients( + message, {"partner_ids": [self.partner.id]} + ) + + for partner in recipients: + self.assertEqual( + partner["notif"], + "inbox", + "Should respect partner's notification preferences", + ) + + # Test with forcing email + recipients = ( + self.env["mail.thread"] + .with_context(force_notification_by_email=True) + ._notify_get_recipients(message, {"partner_ids": [self.partner.id]}) + ) + for partner in recipients: + self.assertEqual( + partner["notif"], + "email", + "Should force email notification regardless of preferences", + )