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

========================
Deferred Message Posting
========================

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

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-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_post_defer
: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_post_defer
: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 enhances mail threads by using the mail queue by default.

Without this module, Odoo attempts to notify recipients of your message
immediately. If your mail server is slow or you have many followers,
this can mean a lot of time. Install this module and make Odoo more
snappy!

All emails will be kept in the outgoing queue by at least 30 seconds,
giving you some time to re-think what you wrote. During that time, you
can still delete the message and start again.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

You usually don't need to do anything. The module is configured
appropriately out of the box. Just make sure the following scheduled
actions are active:

- Mail: Email Queue Manager (mail.ir_cron_mail_scheduler_action)
- Notification: Notify scheduled messages
(mail.ir_cron_send_scheduled_message)

The mail queue processing and scheduled messages notifications are
handled by cron jobs. This is normal Odoo behavior, not specific to this
module. However, since you will start using that queue for every message
posted by any user in any thread, both jobs are configured to execute
every minute by default.

You can still change that cadence after installing the module (although
it is not recommended). To do so:

1. Log in with an administrator user.
2. Activate developer mode.
3. Go to *Settings > Technical > Automation > Scheduled Actions*.
4. Find the cron(s) you want to adjust:

- Mail: Email Queue Manager - handles outgoing emails.
- Notification: Notify scheduled messages - handles notifications.

5. Lower down the frequency in the field *Execute Every*. Recommended: 1
minute.

Usage
=====

To use this module, you need to:

1. Go to the form view of any record that has a mail thread. It can be a
partner, for example.
2. Post a message.

The mail is now in the outgoing mail queue. It will be there for at
least 30 seconds. It will be really sent the next time the "Mail: Email
Queue Manager" cron job is executed.

While the message has not been yet sent:

1. Click the little envelope. You will see a paper airplane icon,
indicating it is still outgoing.
2. Hover over the message and click on *⠇ > 🗑️ Delete*. Mails will not
be sent.

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

- Add minimal deferring time configuration if it ever becomes necessary.
See https://github.com/OCA/social/pull/1001#issuecomment-1461581573
for the rationale behind current hardcoded value of 30 seconds.

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_post_defer%0Aversion:%2019.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
-------

* Moduon
* OERP Canada

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

- Jairo Llopis (https://www.moduon.team/)
- `OERP Canada <https://www.oerp.ca>`__

- Yash Pathak

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

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

|maintainer-Yajo|

This module is part of the `OCA/mail <https://github.com/OCA/mail/tree/19.0/mail_post_defer>`_ 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 mail_post_defer/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
17 changes: 17 additions & 0 deletions mail_post_defer/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2022-2023 Moduon Team S.L. <info@moduon.team>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
{
"name": "Deferred Message Posting",
"summary": "Faster and cancellable outgoing messages",
"version": "19.0.1.0.0",
"development_status": "Alpha",
"category": "Productivity/Discuss",
"website": "https://github.com/OCA/mail",
"author": "Moduon, OERP Canada, Odoo Community Association (OCA)",
"maintainers": ["Yajo"],
"license": "LGPL-3",
"depends": [
"mail",
],
"post_init_hook": "post_init_hook",
}
28 changes: 28 additions & 0 deletions mail_post_defer/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022-2023 Moduon Team S.L. <info@moduon.team>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).
import logging

_logger = logging.getLogger(__name__)


def post_init_hook(env):
"""Increase cadence of mail queue and notification crons."""
crons = {
"mail.ir_cron_mail_scheduler_action": "Mail: Email Queue Manager",
"mail.ir_cron_send_scheduled_message": "Notification: Notify scheduled messages", # noqa: E501
}

for cron_ref, description in crons.items():
try:
cron = env.ref(cron_ref)
except ValueError:
_logger.warning(
"Couldn't find the %s cron (%s). "
"Maybe no mails/notification will be ever sent!.",
description,
cron_ref,
)
else:
_logger.info("Setting %s cron cadence to 1 minute", description)
cron.interval_number = 1
cron.interval_type = "minutes"
39 changes: 39 additions & 0 deletions mail_post_defer/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_post_defer
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-01-09 20:34+0000\n"
"Last-Translator: Ivorra78 <informatica@totmaterial.es>\n"
"Language-Team: none\n"
"Language: es\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 4.17\n"

#. module: mail_post_defer
#. odoo-python
#: code:addons/mail_post_defer/models/mail_thread.py:0
#, python-format
msgid "Cannot modify message; notifications were already sent."
msgstr "No se puede modificar el mensaje; ya se han enviado notificaciones."

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_thread
msgid "Email Thread"
msgstr "Hilo de Correo Electrónico"

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_message
msgid "Message"
msgstr "Mensaje"

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_message_schedule
msgid "Scheduled Messages"
msgstr ""
40 changes: 40 additions & 0 deletions mail_post_defer/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_post_defer
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2024-05-27 12:55+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\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 4.17\n"

#. module: mail_post_defer
#. odoo-python
#: code:addons/mail_post_defer/models/mail_thread.py:0
#, python-format
msgid "Cannot modify message; notifications were already sent."
msgstr ""
"Non si può modificare il messaggio; le notifiche sono già state spedite."

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_thread
msgid "Email Thread"
msgstr "Discussione e-mail"

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_message
msgid "Message"
msgstr "Messaggio"

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_message_schedule
msgid "Scheduled Messages"
msgstr "Messaggi schedulati"
36 changes: 36 additions & 0 deletions mail_post_defer/i18n/mail_post_defer.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * mail_post_defer
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 19.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_post_defer
#: model:ir.model.fields,field_description:mail_post_defer.field_mail_message_schedule__display_name
#: model:ir.model.fields,field_description:mail_post_defer.field_mail_thread__display_name
msgid "Display Name"
msgstr ""

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_thread
msgid "Email Thread"
msgstr ""

#. module: mail_post_defer
#: model:ir.model.fields,field_description:mail_post_defer.field_mail_message_schedule__id
#: model:ir.model.fields,field_description:mail_post_defer.field_mail_thread__id
msgid "ID"
msgstr ""

#. module: mail_post_defer
#: model:ir.model,name:mail_post_defer.model_mail_message_schedule
msgid "Scheduled Messages"
msgstr ""
2 changes: 2 additions & 0 deletions mail_post_defer/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import mail_message_schedule
from . import mail_thread
26 changes: 26 additions & 0 deletions mail_post_defer/models/mail_message_schedule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 Moduon Team S.L. <info@moduon.team>
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl).

from odoo import models


class MailMessageSchedule(models.Model):
_inherit = "mail.message.schedule"

def _send_notifications(self, default_notify_kwargs=None):
"""Avoid deferring notifications when they should be sent."""
_self = self.with_context(mail_defer_seconds=0)
return super(MailMessageSchedule, _self)._send_notifications(
default_notify_kwargs=default_notify_kwargs
)

def _group_by_model(self):
"""Make sure only mail.thread children are grouped with model."""
result = super()._group_by_model()
for model, records in result.copy().items():
# Move records without mail.thread mixin to a False key
if model and not hasattr(self.env.get(model), "_notify_thread"):
result.pop(model)
result.setdefault(False, self.browse())
result[False] += records
return result
Loading