Skip to content

Commit 26d37c8

Browse files
etobellaMiquelRForgeFlow
authored andcommitted
[ADD] mail_quoted_reply
1 parent 0b66a85 commit 26d37c8

17 files changed

+302
-0
lines changed

mail_quoted_reply/README.rst

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
==================
2+
Mail Message Reply
3+
==================
4+
5+
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
6+
!! This file is generated by oca-gen-addon-readme !!
7+
!! changes will be overwritten. !!
8+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
9+
10+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
11+
:target: https://odoo-community.org/page/development-status
12+
:alt: Beta
13+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
14+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
15+
:alt: License: AGPL-3
16+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsocial-lightgray.png?logo=github
17+
:target: https://github.com/OCA/social/tree/12.0/mail_message_reply
18+
:alt: OCA/social
19+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20+
:target: https://translation.odoo-community.org/projects/social-12-0/social-12-0-mail_message_reply
21+
:alt: Translate me on Weblate
22+
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23+
:target: https://runbot.odoo-community.org/runbot/205/12.0
24+
:alt: Try me on Runbot
25+
26+
|badge1| |badge2| |badge3| |badge4| |badge5|
27+
28+
This addon allow to reply on messages from odoo directly.
29+
It is useful when replying to a message from a customer.
30+
31+
**Table of contents**
32+
33+
.. contents::
34+
:local:
35+
36+
Usage
37+
=====
38+
39+
On the messages from threads, a reply button is shown.
40+
Once it has been pressed, a composer with the reply is shown.
41+
42+
Bug Tracker
43+
===========
44+
45+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/social/issues>`_.
46+
In case of trouble, please check there if your issue has already been reported.
47+
If you spotted it first, help us smashing it by providing a detailed and welcomed
48+
`feedback <https://github.com/OCA/social/issues/new?body=module:%20mail_message_reply%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
49+
50+
Do not contact contributors directly about support or help with technical issues.
51+
52+
Credits
53+
=======
54+
55+
Authors
56+
~~~~~~~
57+
58+
* Creu Blanca
59+
60+
Contributors
61+
~~~~~~~~~~~~
62+
63+
* Enric Tobella
64+
65+
Maintainers
66+
~~~~~~~~~~~
67+
68+
This module is maintained by the OCA.
69+
70+
.. image:: https://odoo-community.org/logo.png
71+
:alt: Odoo Community Association
72+
:target: https://odoo-community.org
73+
74+
OCA, or the Odoo Community Association, is a nonprofit organization whose
75+
mission is to support the collaborative development of Odoo features and
76+
promote its widespread use.
77+
78+
This module is part of the `OCA/social <https://github.com/OCA/social/tree/12.0/mail_message_reply>`_ project on GitHub.
79+
80+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

mail_quoted_reply/__init__.py

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizards

mail_quoted_reply/__manifest__.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021 Creu Blanca
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
{
5+
'name': 'Mail Message Reply',
6+
'summary': """
7+
Make a reply using a message""",
8+
'version': '12.0.1.0.0',
9+
'license': 'AGPL-3',
10+
'author': 'Creu Blanca,Odoo Community Association (OCA)',
11+
'website': 'https://github.com/OCA/social',
12+
'depends': [
13+
'mail'
14+
],
15+
'qweb': [
16+
'static/src/xml/mail_message_reply.xml',
17+
],
18+
'data': [
19+
"templates/assets.xml",
20+
"data/reply_template.xml",
21+
],
22+
}
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<odoo>
3+
<record id="reply_template" model="mail.template">
4+
<field name="name">Reply</field>
5+
<field name="subject">Re: ${object.subject}</field>
6+
<field name="use_default_to" eval="True"/>
7+
<field name="model_id" ref="mail.model_mail_message"/>
8+
<field name="body_html"><![CDATA[
9+
<div>
10+
</div>
11+
<br/>
12+
<blockquote style="padding-right:0px; padding-left:5px; border-left-color: #000; margin-left:5px; margin-right:0px;border-left-width: 2px; border-left-style:solid">
13+
From: ${object.email_from}<br/>
14+
Date: ${object.date}<br/>
15+
Subject: ${object.subject}<br/>
16+
${object.body | safe}
17+
</blockquote>
18+
]]></field>
19+
</record>
20+
</odoo>

mail_quoted_reply/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import mail_message
+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2021 Creu Blanca
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
7+
class MailMessage(models.Model):
8+
9+
_inherit = 'mail.message'
10+
11+
def reply_message(self):
12+
action = self.env.ref(
13+
"mail.action_email_compose_message_wizard"
14+
).read()[0]
15+
action['context'] = {
16+
"default_model": self._name,
17+
"default_res_id": self.id,
18+
"default_template_id": self.env.ref(
19+
"mail_quoted_reply.reply_template"
20+
).id,
21+
"default_composition_mode": "comment",
22+
"default_is_log": False,
23+
"is_log": False,
24+
"default_notify": True,
25+
"force_email": True,
26+
"reassign_to_parent": True,
27+
"default_partner_ids": [
28+
(6, 0, self.partner_ids.ids)
29+
]
30+
}
31+
return action
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* Enric Tobella
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This addon allow to reply on messages from odoo directly.
2+
It is useful when replying to a message from a customer.

mail_quoted_reply/readme/USAGE.rst

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
On the messages from threads, a reply button is shown.
2+
Once it has been pressed, a composer with the reply is shown.
9.23 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/* Copyright 2021 Creu Blanca
2+
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
*/
4+
odoo.define('mail_quote_reply.reply', function (require) {
5+
"use strict";
6+
7+
var ThreadWidget = require('mail.widget.Thread');
8+
var ThreadField = require('mail.ThreadField');
9+
var DocumentThread = require('mail.model.DocumentThread');
10+
11+
DocumentThread.include({
12+
_fetchMessages: function(options) {
13+
if (options && options.forceReloadMessages) {
14+
this._mustFetchMessageIDs = true;
15+
}
16+
return this._super.apply(this, arguments)
17+
}
18+
});
19+
20+
ThreadField.include({
21+
start: function () {
22+
var self = this;
23+
return this._super.apply(this, arguments).then(function () {
24+
self._threadWidget.on('reload_thread_messages', self, self._onReloadThreadMessages);
25+
})
26+
},
27+
_onReloadThreadMessages: function () {
28+
this._fetchAndRenderThread({forceReloadMessages: true });
29+
},
30+
});
31+
32+
ThreadWidget.include({
33+
events: _.defaults({
34+
"click .o_thread_mail_message_reply": "_onClickMailMessageReply",
35+
}, ThreadWidget.prototype.events),
36+
37+
_onClickMailMessageReply: function(event) {
38+
var self = this,
39+
msg_id = $(event.currentTarget).data('message-id');
40+
this._rpc({
41+
model: "mail.message",
42+
method: "reply_message",
43+
args: [msg_id],
44+
}).then(function (result) {
45+
self.do_action(result, {
46+
on_close: function () {
47+
self.trigger('reload_thread_messages');
48+
},
49+
});
50+
});
51+
},
52+
});
53+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!-- Copyright 2021 Creu Blanca
3+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
4+
<template>
5+
<t t-extend="mail.widget.Thread.Message">
6+
<t t-jquery=".o_thread_message_reply" t-operation="after">
7+
<i t-if="message.isLinkedToDocumentThread() and !options.displayReplyIcons and !message.isSystemNotification()"
8+
class="fa fa-reply o_thread_icon o_thread_mail_message_reply"
9+
t-att-data-message-id="message.getID()" title="Reply" role="img" aria-label="Reply"/>
10+
</t>
11+
</t>
12+
</template>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!-- Copyright 2014-2015 Grupo ESOC <http://www.grupoesoc.es>
4+
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
5+
6+
<odoo>
7+
8+
<template id="assets_backend"
9+
name="mail_quoted_reply assets"
10+
inherit_id="web.assets_backend">
11+
<xpath expr="." position="inside">
12+
13+
<script type="text/javascript"
14+
src="/mail_quoted_reply/static/src/js/mail_message_reply.js"/>
15+
</xpath>
16+
</template>
17+
</odoo>

mail_quoted_reply/tests/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import test_reply

mail_quoted_reply/tests/test_reply.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Copyright 2021 Creu Blanca
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
from odoo.tests import TransactionCase
4+
5+
6+
class TestMessageReply(TransactionCase):
7+
def test_reply(self):
8+
partner = self.env["res.partner"].create({
9+
"name": "demo partner"
10+
})
11+
self.assertFalse(
12+
partner.message_ids.filtered(
13+
lambda r: r.message_type != 'notification'
14+
)
15+
)
16+
message = partner.message_post(
17+
body="demo message",
18+
message_type="email"
19+
)
20+
partner.refresh()
21+
self.assertIn(
22+
message,
23+
partner.message_ids.filtered(
24+
lambda r: r.message_type != 'notification')
25+
)
26+
self.assertFalse(partner.message_ids.filtered(
27+
lambda r: r.message_type != 'notification' and r != message
28+
))
29+
action = message.reply_message()
30+
wizard = self.env[action["res_model"]].with_context(
31+
action["context"]
32+
).create({})
33+
wizard.action_send_mail()
34+
new_message = partner.message_ids.filtered(
35+
lambda r: r.message_type != 'notification' and r != message
36+
)
37+
self.assertTrue(new_message)
38+
self.assertEqual(1, len(new_message))

mail_quoted_reply/wizards/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import mail_compose_message_reply
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright 2021 Creu Blanca
2+
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
3+
4+
from odoo import models
5+
6+
7+
class MailComposeMessageReply(models.TransientModel):
8+
9+
_inherit = "mail.compose.message"
10+
11+
def send_mail(self, auto_commit=False):
12+
if self.env.context.get("reassign_to_parent"):
13+
for record in self:
14+
if record.model == "mail.message":
15+
parent = self.env[record.model].browse(record.res_id)
16+
record.model = parent.model
17+
record.res_id = parent.res_id
18+
record.parent_id = parent
19+
return super().send_mail(auto_commit=auto_commit)

0 commit comments

Comments
 (0)