diff --git a/mail_notify_employee_leave/README.rst b/mail_notify_employee_leave/README.rst new file mode 100644 index 000000000..7acc97a56 --- /dev/null +++ b/mail_notify_employee_leave/README.rst @@ -0,0 +1,104 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================== +Mail Notify Employee Leave +========================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:d842cebb8364c632fefac6bb11811aceb16efe2d3aa4910c51a56368df2e9bba + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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_notify_employee_leave + :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_notify_employee_leave + :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 automatically notifies users when they mention or assign a +colleague who is out of office. The notification includes the expected +return date of the absent user and is sent only once per day per user. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To trigger the out-of-office notification: + +1. An employee must have an approved leave covering today's date. This + sets the employee's **Is Absent** field automatically. +2. The employee must be linked to an Odoo user. +3. Send any message that includes employee's partner in the recipients, + for example, by mentioning them with ``@name``. + +When these conditions are met, the sender receives an internal note with +the expected return date of the absent employee, calculated as the first +working day after the leave ends based on the employee's working +schedule and public holidays. + +The notification is sent at most once per user per day per employee. +Sending further messages to the same absent employee on the same day +will not produce additional notifications. + +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 +------- + +* ForgeFlow + +Contributors +------------ + +- `ForgeFlow `__: + + - Guillermo Navas + +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_notify_employee_leave/__init__.py b/mail_notify_employee_leave/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/mail_notify_employee_leave/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mail_notify_employee_leave/__manifest__.py b/mail_notify_employee_leave/__manifest__.py new file mode 100644 index 000000000..7a51649de --- /dev/null +++ b/mail_notify_employee_leave/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2026 ForgeFlow S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Mail Notify Employee Leave", + "summary": """ + Notifies users when they mention or assign someone who is out of office. + """, + "version": "19.0.1.0.0", + "license": "AGPL-3", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/mail", + "depends": ["mail", "hr_holidays"], +} diff --git a/mail_notify_employee_leave/i18n/es.po b/mail_notify_employee_leave/i18n/es.po new file mode 100644 index 000000000..954d0afbb --- /dev/null +++ b/mail_notify_employee_leave/i18n/es.po @@ -0,0 +1,66 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notify_employee_leave +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-03-05 10:44+0000\n" +"PO-Revision-Date: 2026-03-05 10:44+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mail_notify_employee_leave +#. odoo-python +#: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 +#, python-format +msgid "%(name)s is out of office, expected back on %(date)s." +msgstr "%(name)s estará fuera de la oficina hasta el %(date)s." + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_date +msgid "Date of Last Absence Notification" +msgstr "Fecha de la última notificación" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_date +msgid "Date of the last notification record" +msgstr "Fecha del último registro de notificaciones" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_mail_thread +msgid "Email Thread" +msgstr "Hilo de correo electrónico" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_hr_employee +msgid "Employee" +msgstr "Empleado" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_hr_leave +msgid "Time Off" +msgstr "Ausencias" + +#. module: mail_notify_employee_leave +#. odoo-python +#: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 +#, python-format +msgid "User out of office" +msgstr "Usuario fuera de la oficina" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids +msgid "Users Notified Today" +msgstr "Usuarios notificados hoy" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids +msgid "Users who have already been notified today about this absence" +msgstr "Usuarios que ya fueron notificados hoy sobre esta ausencia" diff --git a/mail_notify_employee_leave/i18n/it.po b/mail_notify_employee_leave/i18n/it.po new file mode 100644 index 000000000..f5bf1dfd3 --- /dev/null +++ b/mail_notify_employee_leave/i18n/it.po @@ -0,0 +1,66 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notify_employee_leave +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-05-11 17:45+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.15.2\n" + +#. module: mail_notify_employee_leave +#. odoo-python +#: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 +#, python-format +msgid "%(name)s is out of office, expected back on %(date)s." +msgstr "%(name)s è fuori dall'ufficio, previsto rientro il %(date)s." + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_date +msgid "Date of Last Absence Notification" +msgstr "Data ultima notifica assenza" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_date +msgid "Date of the last notification record" +msgstr "Data dell'ultimo record di notifica" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_mail_thread +msgid "Email Thread" +msgstr "Discussione e-mail" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_hr_employee +msgid "Employee" +msgstr "Dipendente" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_hr_leave +msgid "Time Off" +msgstr "Ferie" + +#. module: mail_notify_employee_leave +#. odoo-python +#: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 +#, python-format +msgid "User out of office" +msgstr "Utente fuori ufficio" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids +msgid "Users Notified Today" +msgstr "Utente avvisato oggi" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids +msgid "Users who have already been notified today about this absence" +msgstr "Utenti che sono già stati informati oggi di questa assenza" diff --git a/mail_notify_employee_leave/i18n/mail_notify_employee_leave.pot b/mail_notify_employee_leave/i18n/mail_notify_employee_leave.pot new file mode 100644 index 000000000..b2f2a98b5 --- /dev/null +++ b/mail_notify_employee_leave/i18n/mail_notify_employee_leave.pot @@ -0,0 +1,63 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mail_notify_employee_leave +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.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_notify_employee_leave +#. odoo-python +#: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 +#, python-format +msgid "%(name)s is out of office, expected back on %(date)s." +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_date +msgid "Date of Last Absence Notification" +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_date +msgid "Date of the last notification record" +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_mail_thread +msgid "Email Thread" +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_hr_employee +msgid "Employee" +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model,name:mail_notify_employee_leave.model_hr_leave +msgid "Time Off" +msgstr "" + +#. module: mail_notify_employee_leave +#. odoo-python +#: code:addons/mail_notify_employee_leave/models/mail_thread.py:0 +#, python-format +msgid "User out of office" +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,field_description:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids +msgid "Users Notified Today" +msgstr "" + +#. module: mail_notify_employee_leave +#: model:ir.model.fields,help:mail_notify_employee_leave.field_hr_employee__absence_notified_user_ids +msgid "Users who have already been notified today about this absence" +msgstr "" diff --git a/mail_notify_employee_leave/models/__init__.py b/mail_notify_employee_leave/models/__init__.py new file mode 100644 index 000000000..c99dbc1e2 --- /dev/null +++ b/mail_notify_employee_leave/models/__init__.py @@ -0,0 +1,3 @@ +from . import mail_thread +from . import hr_leave +from . import hr_employee diff --git a/mail_notify_employee_leave/models/hr_employee.py b/mail_notify_employee_leave/models/hr_employee.py new file mode 100644 index 000000000..89363bd29 --- /dev/null +++ b/mail_notify_employee_leave/models/hr_employee.py @@ -0,0 +1,19 @@ +from odoo import fields, models + + +class HrEmployee(models.Model): + _inherit = "hr.employee" + + absence_notified_user_ids = fields.Many2many( + "res.users", + string="Users Notified Today", + readonly=True, + copy=False, + help="Users who have already been notified today about this absence", + ) + absence_notified_date = fields.Date( + string="Date of Last Absence Notification", + readonly=True, + copy=False, + help="Date of the last notification record", + ) diff --git a/mail_notify_employee_leave/models/hr_leave.py b/mail_notify_employee_leave/models/hr_leave.py new file mode 100644 index 000000000..781e67b89 --- /dev/null +++ b/mail_notify_employee_leave/models/hr_leave.py @@ -0,0 +1,15 @@ +from odoo import models + + +class HrLeave(models.Model): + _inherit = "hr.leave" + + def _validate_leave_request(self): + """ + Override _validate_leave_request to skip absence notifications when + approving leaves. The context flag 'skip_absence_notification' prevents + _notify_thread from sending messages, + """ + return super( + HrLeave, self.with_context(skip_absence_notification=True) + )._validate_leave_request() diff --git a/mail_notify_employee_leave/models/mail_thread.py b/mail_notify_employee_leave/models/mail_thread.py new file mode 100644 index 000000000..0729166a9 --- /dev/null +++ b/mail_notify_employee_leave/models/mail_thread.py @@ -0,0 +1,44 @@ +from odoo import fields, models + + +class MailThread(models.AbstractModel): + _inherit = "mail.thread" + + def _notify_thread(self, message, msg_vals=False, **kwargs): + recipients_data = super()._notify_thread(message, msg_vals=msg_vals, **kwargs) + if self.env.context.get("skip_absence_notification"): + return recipients_data + + affected_partner_ids = message.partner_ids.ids + + today = fields.Date.today() + + for partner_id in affected_partner_ids: + partner = self.env["res.partner"].browse(partner_id) + employee = ( + self.env["hr.employee"] + .sudo() + .search([("user_id.partner_id", "=", partner.id)], limit=1) + ) + if employee and employee.is_absent: + if employee.absence_notified_date != today: + employee.absence_notified_user_ids = [(5, 0, 0)] + employee.absence_notified_date = today + + if self.env.user not in employee.absence_notified_user_ids: + back_date = employee.leave_date_to + body = self.env._( + "%(name)s is out of office, expected back on %(date)s.", + name=employee.name, + date=fields.Date.to_string(back_date), + ) + self.message_notify( + partner_ids=[self.env.user.partner_id.id], + body=body, + subject=self.env._("User out of office"), + subtype_xmlid="mail.mt_note", + notify_author=True, + ) + employee.absence_notified_user_ids = [(4, self.env.user.id)] + + return recipients_data diff --git a/mail_notify_employee_leave/pyproject.toml b/mail_notify_employee_leave/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_notify_employee_leave/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_notify_employee_leave/readme/CONTRIBUTORS.md b/mail_notify_employee_leave/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..2f1465d02 --- /dev/null +++ b/mail_notify_employee_leave/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [ForgeFlow](https://www.forgeflow.com): + - Guillermo Navas \<\> diff --git a/mail_notify_employee_leave/readme/DESCRIPTION.md b/mail_notify_employee_leave/readme/DESCRIPTION.md new file mode 100644 index 000000000..5e9f4bcf0 --- /dev/null +++ b/mail_notify_employee_leave/readme/DESCRIPTION.md @@ -0,0 +1,3 @@ +This module automatically notifies users when they mention or assign +a colleague who is out of office. The notification includes the expected +return date of the absent user and is sent only once per day per user. \ No newline at end of file diff --git a/mail_notify_employee_leave/readme/USAGE.md b/mail_notify_employee_leave/readme/USAGE.md new file mode 100644 index 000000000..f6a9fee86 --- /dev/null +++ b/mail_notify_employee_leave/readme/USAGE.md @@ -0,0 +1,16 @@ +To trigger the out-of-office notification: + +1. An employee must have an approved leave covering today's date. This sets + the employee's **Is Absent** field automatically. +2. The employee must be linked to an Odoo user. +3. Send any message that includes employee's partner in the recipients, + for example, by mentioning them with `@name`. + +When these conditions are met, the sender receives an internal note with the +expected return date of the absent employee, calculated as the first working +day after the leave ends based on the employee's working schedule and public +holidays. + +The notification is sent at most once per user per day per employee. Sending +further messages to the same absent employee on the same day will not produce +additional notifications. diff --git a/mail_notify_employee_leave/static/description/icon.png b/mail_notify_employee_leave/static/description/icon.png new file mode 100644 index 000000000..1dcc49c24 Binary files /dev/null and b/mail_notify_employee_leave/static/description/icon.png differ diff --git a/mail_notify_employee_leave/static/description/index.html b/mail_notify_employee_leave/static/description/index.html new file mode 100644 index 000000000..709d24c33 --- /dev/null +++ b/mail_notify_employee_leave/static/description/index.html @@ -0,0 +1,453 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mail Notify Employee Leave

+ +

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

+

This module automatically notifies users when they mention or assign a +colleague who is out of office. The notification includes the expected +return date of the absent user and is sent only once per day per user.

+

Table of contents

+ +
+

Usage

+

To trigger the out-of-office notification:

+
    +
  1. An employee must have an approved leave covering today’s date. This +sets the employee’s Is Absent field automatically.
  2. +
  3. The employee must be linked to an Odoo user.
  4. +
  5. Send any message that includes employee’s partner in the recipients, +for example, by mentioning them with @name.
  6. +
+

When these conditions are met, the sender receives an internal note with +the expected return date of the absent employee, calculated as the first +working day after the leave ends based on the employee’s working +schedule and public holidays.

+

The notification is sent at most once per user per day per employee. +Sending further messages to the same absent employee on the same day +will not produce additional notifications.

+
+
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

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_notify_employee_leave/tests/__init__.py b/mail_notify_employee_leave/tests/__init__.py new file mode 100644 index 000000000..ddabba994 --- /dev/null +++ b/mail_notify_employee_leave/tests/__init__.py @@ -0,0 +1 @@ +from . import test_mail_notify_employee_leave diff --git a/mail_notify_employee_leave/tests/test_mail_notify_employee_leave.py b/mail_notify_employee_leave/tests/test_mail_notify_employee_leave.py new file mode 100644 index 000000000..5e0decd5a --- /dev/null +++ b/mail_notify_employee_leave/tests/test_mail_notify_employee_leave.py @@ -0,0 +1,107 @@ +# Copyright 2026 ForgeFlow S.L. +# (http://www.forgeflow.com) +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from datetime import timedelta + +from odoo import fields +from odoo.tests.common import TransactionCase + + +class TestNotifyEmployeeLeave(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + + internal_group = cls.env.ref("base.group_user") + partner_manager_group = cls.env.ref("base.group_partner_manager") + + cls.user = cls.env["res.users"].create( + { + "name": "Test User", + "login": "test_user", + "email": "test@example.com", + "notification_type": "inbox", + "group_ids": [(4, internal_group.id), (4, partner_manager_group.id)], + } + ) + + cls.absent_user = cls.env["res.users"].create( + { + "name": "Absent User", + "login": "absent_user", + "email": "absent@example.com", + "notification_type": "inbox", + "group_ids": [(4, internal_group.id)], + } + ) + + cls.partner = cls.absent_user.partner_id + + cls.employee = cls.env["hr.employee"].create( + { + "name": "Absent Employee", + "user_id": cls.absent_user.id, + } + ) + + cls.leave_type = cls.env["hr.leave.type"].create( + { + "name": "Test Leave", + "leave_validation_type": "no_validation", + "requires_allocation": False, + } + ) + + cls.record = cls.env["res.partner"].create({"name": "Test Record"}) + + @classmethod + def _create_validated_leave(cls): + today = fields.Date.today() + leave = ( + cls.env["hr.leave"] + .with_context(skip_absence_notification=True) + .create( + { + "holiday_status_id": cls.leave_type.id, + "employee_id": cls.employee.id, + "request_date_from": today - timedelta(days=1), + "request_date_to": today + timedelta(days=1), + } + ) + ) + leave.sudo()._action_validate() + return leave + + def test_no_notify_when_user_not_absent(self): + self.record.with_user(self.user).message_post( + body="Test message", partner_ids=[self.partner.id] + ) + + self.assertNotIn(self.user, self.employee.absence_notified_user_ids) + + def test_notify_when_user_absent(self): + self._create_validated_leave() + + self.record.with_user(self.user).message_post( + body="Test message", partner_ids=[self.partner.id] + ) + + self.assertIn(self.user, self.employee.absence_notified_user_ids) + self.assertEqual(self.employee.absence_notified_date, fields.Date.today()) + + def test_only_one_notification_per_day(self): + self._create_validated_leave() + + self.record.with_user(self.user).message_post( + body="Test message 1", partner_ids=[self.partner.id] + ) + + self.record.with_user(self.user).message_post( + body="Test message 2", partner_ids=[self.partner.id] + ) + + notified_users = self.employee.absence_notified_user_ids + self.assertEqual(len(notified_users), 1) + self.assertIn(self.user, notified_users) + self.assertEqual(self.employee.absence_notified_date, fields.Date.today()) diff --git a/mail_post_defer/models/mail_thread.py b/mail_post_defer/models/mail_thread.py index 40ba0da2a..6da39f28b 100644 --- a/mail_post_defer/models/mail_thread.py +++ b/mail_post_defer/models/mail_thread.py @@ -4,6 +4,7 @@ from datetime import timedelta from odoo import fields, models +from odoo.tools import config class MailThread(models.AbstractModel): @@ -11,6 +12,9 @@ class MailThread(models.AbstractModel): def _notify_thread(self, message, msg_vals=False, **kwargs): """Defer emails by default.""" + # During tests, don't defer unless a test explicitly opts in + if config["test_enable"] and not self.env.context.get("test_mail_post_defer"): + return super()._notify_thread(message, msg_vals=msg_vals, **kwargs) # Don't defer automatically if forcing send _self = self if "mail_defer_seconds" not in _self.env.context: diff --git a/mail_post_defer/tests/test_mail.py b/mail_post_defer/tests/test_mail.py index 7122b3ac4..95a65f38a 100644 --- a/mail_post_defer/tests/test_mail.py +++ b/mail_post_defer/tests/test_mail.py @@ -17,6 +17,8 @@ class MailPostDeferCommon(MailCommon): def setUpClass(cls): super().setUpClass() cls.classPatch(cls.cr, "now", datetime.now) + # Opt in to deferring during tests + cls.env = cls.env(context=dict(cls.env.context, test_mail_post_defer=True)) cls._create_portal_user() # Notify employee by email cls.user_employee.notification_type = "email"