Skip to content

Commit

Permalink
[IMP] mail_forward: Add option to forward a message to another thread
Browse files Browse the repository at this point in the history
This option posts a new message in the other thread, including the attachments, but does not add them as followers—only notifying the current followers of the other thread.
  • Loading branch information
carlos-lopez-tecnativa committed Jan 24, 2025
1 parent 679bcfa commit c956fb9
Show file tree
Hide file tree
Showing 12 changed files with 317 additions and 43 deletions.
24 changes: 19 additions & 5 deletions mail_forward/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ Mail Forward Message
|badge1| |badge2| |badge3| |badge4| |badge5|

This module allows users to forward messages from the chatter of any
document to other users, adding them as followers of the document
without notifying the current followers.
document to:

- Other users in the same thread, adding them as followers of the
document without notifying the current followers.
- Another thread, but not adding them as followers—only notifying the
current followers of the other thread.

**Table of contents**

Expand All @@ -47,9 +51,11 @@ To use this module, follow these steps:
notes).
- A Forward icon will appear next to the message.
- Click the button to display a wizard with the message.
- Select the users to forward the message to.
- Click the 'Send Mail' button to send the message to the selected
users.
- Select the forward type (current thread or another thread).
- Select the users to forward the message to, or select the other thread
according to the previous step.
- Click the 'Send Mail' button to send the message to the selected users
or thread.

Bug Tracker
===========
Expand Down Expand Up @@ -89,6 +95,14 @@ 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-carlos-lopez-tecnativa| image:: https://github.com/carlos-lopez-tecnativa.png?size=40px
:target: https://github.com/carlos-lopez-tecnativa
:alt: carlos-lopez-tecnativa

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

|maintainer-carlos-lopez-tecnativa|

This module is part of the `OCA/social <https://github.com/OCA/social/tree/17.0/mail_forward>`_ 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_forward/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
"installable": True,
"auto_install": False,
"license": "AGPL-3",
"maintainers": ["carlos-lopez-tecnativa"],
}
30 changes: 25 additions & 5 deletions mail_forward/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-10-02 12:25+0000\n"
"PO-Revision-Date: 2024-10-02 07:27-0500\n"
Expand All @@ -24,6 +24,16 @@ msgstr ""
msgid "---------- Forwarded message ---------"
msgstr "---------- Mensaje reenviado ---------"

#. module: mail_forward
#: model:ir.model.fields.selection,name:mail_forward.selection__mail_compose_message__forward_type__another_thread
msgid "Another thread"
msgstr "Otro hilo"

#. module: mail_forward
#: model:ir.model.fields.selection,name:mail_forward.selection__mail_compose_message__forward_type__current_thread
msgid "Current thread"
msgstr "Hilo actual"

#. module: mail_forward
#. odoo-python
#: code:addons/mail_forward/models/mail_message.py:0
Expand All @@ -34,20 +44,20 @@ msgstr "Fecha"
#. module: mail_forward
#: model:ir.model,name:mail_forward.model_mail_thread
msgid "Email Thread"
msgstr "Hilo de correos electrónicos"
msgstr "Hilo de correo electrónico"

#. module: mail_forward
#: model:ir.model,name:mail_forward.model_mail_compose_message
msgid "Email composition wizard"
msgstr "Asistente de composición de correos electrónicos"
msgstr "Asistente de redacción de correo electrónico"

#. module: mail_forward
#. odoo-javascript
#: code:addons/mail_forward/static/src/components/forward_message/forward_message.xml:0
#: code:addons/mail_forward/static/src/core/common/message_actions.esm.js:0
#, python-format
msgid "Forward"
msgstr ""
msgstr "Reenviar"

#. module: mail_forward
#. odoo-javascript
Expand Down Expand Up @@ -79,6 +89,11 @@ msgstr ""
msgid "Forward Message Right"
msgstr ""

#. module: mail_forward
#: model:ir.model.fields,field_description:mail_forward.field_mail_compose_message__forward_type
msgid "Forward Type"
msgstr "Tipo de reenvío"

#. module: mail_forward
#. odoo-python
#: code:addons/mail_forward/models/mail_message.py:0
Expand All @@ -91,7 +106,7 @@ msgstr "De"
#: code:addons/mail_forward/wizards/mail_compose_message.py:0
#, python-format
msgid "Fwd:"
msgstr ""
msgstr "Re:"

#. module: mail_forward
#: model:ir.model,name:mail_forward.model_mail_message
Expand All @@ -112,6 +127,11 @@ msgstr ""
msgid "Subject"
msgstr "Asunto"

#. module: mail_forward
#: model:ir.model.fields,field_description:mail_forward.field_mail_compose_message__forward_thread
msgid "Thread to forward"
msgstr "Hilo a reenviar"

#. module: mail_forward
#. odoo-python
#: code:addons/mail_forward/models/mail_message.py:0
Expand Down
20 changes: 20 additions & 0 deletions mail_forward/i18n/mail_forward.pot
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ msgstr ""
msgid "---------- Forwarded message ---------"
msgstr ""

#. module: mail_forward
#: model:ir.model.fields.selection,name:mail_forward.selection__mail_compose_message__forward_type__another_thread
msgid "Another thread"
msgstr ""

#. module: mail_forward
#: model:ir.model.fields.selection,name:mail_forward.selection__mail_compose_message__forward_type__current_thread
msgid "Current thread"
msgstr ""

#. module: mail_forward
#. odoo-python
#: code:addons/mail_forward/models/mail_message.py:0
Expand Down Expand Up @@ -76,6 +86,11 @@ msgstr ""
msgid "Forward Message Right"
msgstr ""

#. module: mail_forward
#: model:ir.model.fields,field_description:mail_forward.field_mail_compose_message__forward_type
msgid "Forward Type"
msgstr ""

#. module: mail_forward
#. odoo-python
#: code:addons/mail_forward/models/mail_message.py:0
Expand Down Expand Up @@ -109,6 +124,11 @@ msgstr ""
msgid "Subject"
msgstr ""

#. module: mail_forward
#: model:ir.model.fields,field_description:mail_forward.field_mail_compose_message__forward_thread
msgid "Thread to forward"
msgstr ""

#. module: mail_forward
#. odoo-python
#: code:addons/mail_forward/models/mail_message.py:0
Expand Down
2 changes: 0 additions & 2 deletions mail_forward/models/mail_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def action_wizard_forward(self):
"default_model": self.model,
"default_res_ids": [self.res_id],
"default_composition_mode": "comment",
"default_body": self._build_message_body_for_forward(),
"default_attachment_ids": self.attachment_ids.ids,
"default_is_log": False,
"default_notify": True,
"force_email": True,
Expand Down
5 changes: 4 additions & 1 deletion mail_forward/models/mail_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ class MailThread(models.AbstractModel):
def _notify_get_recipients(self, message, msg_vals, **kwargs):
recipients_data = super()._notify_get_recipients(message, msg_vals, **kwargs)
# only notify to explicit partners, remove others(followers).
if self.env.context.get("message_forwarded_id"):
if (
self.env.context.get("message_forwarded_id")
and self.env.context.get("forward_type", "") == "current_thread"
):
current_partners_ids = message.partner_ids.ids
new_recipeints = []
for recipeint in recipients_data:
Expand Down
6 changes: 3 additions & 3 deletions mail_forward/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
This module allows users to forward messages from the chatter of any
document to other users, adding them as followers of the document
without notifying the current followers.
This module allows users to forward messages from the chatter of any document to:
- Other users in the same thread, adding them as followers of the document without notifying the current followers.
- Another thread, but not adding them as followers—only notifying the current followers of the other thread.
7 changes: 4 additions & 3 deletions mail_forward/readme/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ To use this module, follow these steps:
notes).
- A Forward icon will appear next to the message.
- Click the button to display a wizard with the message.
- Select the users to forward the message to.
- Click the 'Send Mail' button to send the message to the selected
users.
- Select the forward type (current thread or another thread).
- Select the users to forward the message to, or select the other thread according to the previous step.
- Click the 'Send Mail' button to send the message to the selected users or thread.

19 changes: 14 additions & 5 deletions mail_forward/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,13 @@ <h1 class="title">Mail Forward Message</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/social/tree/17.0/mail_forward"><img alt="OCA/social" src="https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/social-17-0/social-17-0-mail_forward"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/social&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows users to forward messages from the chatter of any
document to other users, adding them as followers of the document
without notifying the current followers.</p>
document to:</p>
<ul class="simple">
<li>Other users in the same thread, adding them as followers of the
document without notifying the current followers.</li>
<li>Another thread, but not adding them as followers—only notifying the
current followers of the other thread.</li>
</ul>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand All @@ -395,9 +400,11 @@ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
notes).</li>
<li>A Forward icon will appear next to the message.</li>
<li>Click the button to display a wizard with the message.</li>
<li>Select the users to forward the message to.</li>
<li>Click the ‘Send Mail’ button to send the message to the selected
users.</li>
<li>Select the forward type (current thread or another thread).</li>
<li>Select the users to forward the message to, or select the other thread
according to the previous step.</li>
<li>Click the ‘Send Mail’ button to send the message to the selected users
or thread.</li>
</ul>
</div>
<div class="section" id="bug-tracker">
Expand Down Expand Up @@ -434,6 +441,8 @@ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
<p>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.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/carlos-lopez-tecnativa"><img alt="carlos-lopez-tecnativa" src="https://github.com/carlos-lopez-tecnativa.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/social/tree/17.0/mail_forward">OCA/social</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
55 changes: 55 additions & 0 deletions mail_forward/tests/test_mail_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,61 @@ def test_01_mail_forward(self):
self.assertIn(self.partner_forward, forward_message.partner_ids)
self.assertIn("---------- Forwarded message ---------", forward_message.body)

def test_mail_forward_another_thread(self):
"""
Check that the email is forwarded to another thread.
and the email is sent to the followers of the another thread.
"""
ctx = {
"default_model": self.test_record._name,
"default_res_ids": [self.test_record.id],
}
composer_form = Form(self.env["mail.compose.message"].with_context(**ctx))
composer_form.body = "<p>Hello</p>"
composer_form.subject = "Test Forward"
composer_form.partner_ids.add(self.partner_follower1)
composer = composer_form.save()
with self.mock_mail_gateway():
composer._action_send_mail()
# Verify recipients of mail.message
message = self.test_record.message_ids[0]
self.assertEqual(len(message.partner_ids), 1)
self.assertIn(self.partner_follower1, message.partner_ids)
self.assertNotIn(self.partner_follower2, message.partner_ids)
self.assertNotIn(self.partner_forward, message.partner_ids)
self.assertNotIn("---------- Forwarded message ---------", message.body)
# Forward the email to another record(self.partner_forward)
action_forward = message.action_wizard_forward()
Message = self.env["mail.compose.message"].with_context(
**action_forward["context"]
)
composer_form = Form(Message, view=action_forward["views"][0][0])
composer_form.partner_ids.add(self.partner_follower2)
composer_form.forward_type = "another_thread"
composer_form.forward_thread = (
f"{self.partner_forward._name},{self.partner_forward.id}"
)
composer = composer_form.save()
message_domain = [
("model", "=", self.partner_forward._name),
("res_id", "=", self.partner_forward.id),
]
with RecordCapturer(self.env["mail.message"], message_domain) as capture:
with self.mock_mail_gateway():
composer._action_send_mail()
# Verify recipients of mail.message
forward_message = capture.records
self.assertEqual(forward_message.subject, "Fwd: Test Forward")
self.assertEqual(len(forward_message.partner_ids), 1)
self.assertNotIn(self.partner_follower1, forward_message.partner_ids)
# the partner partner_follower2 is added to the message
# but is not added as a follower automatically.
self.assertIn(self.partner_follower2, forward_message.partner_ids)
self.assertNotIn(
self.partner_follower2, self.partner_forward.message_partner_ids
)
self.assertIn("---------- Forwarded message ---------", forward_message.body)

def test_02_mail_forward_tour(self):
self.test_record.message_post(
body="Hello World", message_type="comment", subtype_xmlid="mail.mt_comment"
Expand Down
Loading

0 comments on commit c956fb9

Please sign in to comment.