Skip to content
Draft
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
110 changes: 110 additions & 0 deletions mail_always_notify_in_odoo/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=====================
Always Notify In Odoo
=====================

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

.. |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/20.0/mail_always_notify_in_odoo
:alt: OCA/mail
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/mail-20-0/mail-20-0-mail_always_notify_in_odoo
: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=20.0
:alt: Try me on Runboat

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

Force notification of internal users via odoo inbox regardless of
whether their email was in To:/Cc:

Odoo avoids notifying internal users about inbound messages if their
email is already in the To or CC header. The assumption is that the user
will be notified via their email inbox and should not be notified again
of the same message in odoo.

However, some companies may desire to force their users to engage with
odoo-related mail exclusively via odoo in order to avoid situations
where the user replies directly to the customer alone via email without
CC'ing the odoo alias, thereby creating a situation where communication
is divided between odoo and email.

**Table of contents**

.. contents::
:local:

Usage
=====

No special configuration needed.

Note that on install and upgrade all internall users will be checked for
and coerced into ``mail.group_mail_notification_type_inbox``.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/mail/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/mail/issues/new?body=module:%20mail_always_notify_in_odoo%0Aversion:%2020.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
-------

* Pyxiris

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

- `Pyxiris <https://github.com/Pyxiris>`__

- `Liam Noonan <https://github.com/ljmnoonan>`__

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-ljmnoonan| image:: https://github.com/ljmnoonan.png?size=40px
:target: https://github.com/ljmnoonan
:alt: ljmnoonan

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

|maintainer-ljmnoonan|

This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/20.0/mail_always_notify_in_odoo>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions mail_always_notify_in_odoo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
28 changes: 28 additions & 0 deletions mail_always_notify_in_odoo/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2026 Liam Noonan
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Always Notify In Odoo",
"summary": "Notify internal users in Odoo, including mail sent to them",
"version": "20.0.1.0.0",
"category": "Productivity/Discuss",
"website": "https://github.com/OCA/mail",
"author": "Pyxiris, Odoo Community Association (OCA)",
"license": "AGPL-3",
"development_status": "Beta",
"maintainers": ["ljmnoonan"],
"depends": ["mail"],
"data": [
"data/force_internal_inbox.xml",
"views/res_users_views.xml",
],
"assets": {
"web.assets_backend": [
"mail_always_notify_in_odoo/static/src/core/**/*",
],
"web.assets_tests": [
"mail_always_notify_in_odoo/static/tests/tours/**/*",
],
},
"installable": True,
}
5 changes: 5 additions & 0 deletions mail_always_notify_in_odoo/data/force_internal_inbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<!-- Apply on install and upgrade so existing internal users move to In Odoo. -->
<function model="res.users" name="_initial_force_notification_type_inbox" />
</odoo>
1 change: 1 addition & 0 deletions mail_always_notify_in_odoo/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import mail_thread, res_users
90 changes: 90 additions & 0 deletions mail_always_notify_in_odoo/models/mail_thread.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# Copyright 2026 Liam Noonan
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import Command, models
from odoo.tools.mail import email_normalize, email_split_and_format


class MailThread(models.AbstractModel):
_inherit = "mail.thread"

def _notify_get_recipients(self, message, **kwargs):
"""Notify in odoo (inbox)internal users addressed on an incoming email.

Core skips addresses on the incoming To/Cc, in order to avoid duplicate
notifications.
The point of this module is to notify internal users via odoo regardless.
In order to acheive this we stash the original headers (incoming_email_to...)
and the original partners called out on the message (partner_ids...).
Then we add the internal partners found in the email headers as if they were
mentioned or followers, and remove the addresses of the internal partners from
the incoming email headers.
This allows the super function to work as normal and build recipients_data
without throwing out the internal partners in the email headers.
Finally, we restore the original headers and partners to the message so as not
to interfere with subsequent logic.
"""
if message.message_type != "email":
return super()._notify_get_recipients(message, **kwargs)

partners_to, partners_cc = self._incoming_internal_partners(message)
if not partners_to and not partners_cc:
return super()._notify_get_recipients(message, **kwargs)

message = message.sudo()
saved_partners = message.partner_ids
saved_partners_cc = message.partner_cc_ids
saved_to = message.incoming_email_to
saved_cc = message.incoming_email_cc
partner_emails = {
email
for email in (partners_to | partners_cc).mapped("email_normalized")
if email
}
message.write(
{
"partner_ids": [Command.link(partner.id) for partner in partners_to],
"partner_cc_ids": [Command.link(partner.id) for partner in partners_cc],
"incoming_email_to": self._emails_without(saved_to, partner_emails),
"incoming_email_cc": self._emails_without(saved_cc, partner_emails),
}
)
try:
return super()._notify_get_recipients(message, **kwargs)
finally:
message.write(
{
"partner_ids": [Command.set(saved_partners.ids)],
"partner_cc_ids": [Command.set(saved_partners_cc.ids)],
"incoming_email_to": saved_to,
"incoming_email_cc": saved_cc,
}
)

def _incoming_internal_partners(self, message):
"""Internal users on the incoming To and Cc, as two recordsets."""
message = message.sudo()
partners_to = self._internal_partners_from_emails(message.incoming_email_to)
partners_cc = self._internal_partners_from_emails(message.incoming_email_cc)
# Prefer "To" when the same address appears in both "To" and "Cc".
return partners_to, partners_cc - partners_to

def _internal_partners_from_emails(self, value):
emails = email_split_and_format(value or "")
if not emails:
return self.env["res.partner"]
return self.env["mail.thread"]._partner_find_from_emails_single(
emails,
no_create=True,
filter_found=lambda partner: any(
not user.share for user in partner.user_ids
),
)

def _emails_without(self, header_value, emails_to_remove):
"""Rebuild a To/Cc header string without the given normalized addresses."""
remaining = []
for address in email_split_and_format(header_value or ""):
if email_normalize(address) not in emails_to_remove:
remaining.append(address)
return ", ".join(remaining)
57 changes: 57 additions & 0 deletions mail_always_notify_in_odoo/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2026 Liam Noonan
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import Command, api, models

from odoo.addons.base.models.res_users import NO_GROUP_CHANGE_LOG


class ResUsers(models.Model):
_inherit = "res.users"

@api.model_create_multi
def create(self, vals_list):
users = super().create(vals_list)
# An explicit notification_type in the create values is stored as-is
# and does not run the compute.
if not self.env.context.get("forcing_notification_type_inbox"):
users._compute_notification_type()
return users

def write(self, vals):
res = super().write(vals)
# Writing notification_type marks the field as user-set, so the group
# change made by its inverse does not recompute it.
if (
not self.env.context.get("forcing_notification_type_inbox")
and "notification_type" in vals
):
self._compute_notification_type()
return res

@api.depends("share", "all_group_ids")
def _compute_notification_type(self):
if not self.env.context.get("forcing_notification_type_inbox"):
self._force_notification_type_inbox()
return super()._compute_notification_type()

def _force_notification_type_inbox(self):
"""Link the inbox group on internal users who are missing it."""
inbox_group_id = self.env["ir.model.data"]._xmlid_to_res_id(
"mail.group_mail_notification_type_inbox"
)
missing = self.filtered(
lambda user: not user.share and inbox_group_id not in user.group_ids.ids
)
if not inbox_group_id or not missing:
return
missing.with_context(
forcing_notification_type_inbox=True,
no_group_change_log=NO_GROUP_CHANGE_LOG,
).sudo().write({"group_ids": [Command.link(inbox_group_id)]})

@api.model
def _initial_force_notification_type_inbox(self):
"""Recompute all users on install"""
users = self.search([("share", "=", False)])
users._compute_notification_type()
3 changes: 3 additions & 0 deletions mail_always_notify_in_odoo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
2 changes: 2 additions & 0 deletions mail_always_notify_in_odoo/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- [Pyxiris](https://github.com/Pyxiris)
- [Liam Noonan](https://github.com/ljmnoonan)
5 changes: 5 additions & 0 deletions mail_always_notify_in_odoo/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Force notification of internal users via odoo inbox regardless of whether their email was in To:/Cc:

Odoo avoids notifying internal users about inbound messages if their email is already in the To or CC header. The assumption is that the user will be notified via their email inbox and should not be notified again of the same message in odoo.

However, some companies may desire to force their users to engage with odoo-related mail exclusively via odoo in order to avoid situations where the user replies directly to the customer alone via email without CC'ing the odoo alias, thereby creating a situation where communication is divided between odoo and email.
3 changes: 3 additions & 0 deletions mail_always_notify_in_odoo/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
No special configuration needed.

Note that on install and upgrade all internall users will be checked for and coerced into `mail.group_mail_notification_type_inbox`.
Loading
Loading