diff --git a/mail_quoted_reply/__init__.py b/mail_quoted_reply/__init__.py index aee8895..0650744 100644 --- a/mail_quoted_reply/__init__.py +++ b/mail_quoted_reply/__init__.py @@ -1,2 +1 @@ from . import models -from . import wizards diff --git a/mail_quoted_reply/__manifest__.py b/mail_quoted_reply/__manifest__.py index b001a9a..e5a5134 100644 --- a/mail_quoted_reply/__manifest__.py +++ b/mail_quoted_reply/__manifest__.py @@ -5,14 +5,19 @@ "name": "Mail Message Reply", "summary": """ Make a reply using a message""", - "version": "14.0.1.0.0", + "version": "15.0.1.0.0", "license": "AGPL-3", "author": "Creu Blanca,Odoo Community Association (OCA)", "website": "https://github.com/OCA/social", "depends": ["mail"], - "qweb": ["static/src/xml/mail_message_reply.xml"], - "data": [ - "templates/assets.xml", - "data/reply_template.xml", - ], + "data": [], + "assets": { + "web.assets_qweb": [ + "/mail_quoted_reply/static/src/xml/mail_message_reply.xml", + ], + "web.assets_backend": [ + "/mail_quoted_reply/static/src/models/mail_message_reply.esm.js", + "/mail_quoted_reply/static/src/components/mail_message_reply.esm.js", + ], + }, } diff --git a/mail_quoted_reply/data/reply_template.xml b/mail_quoted_reply/data/reply_template.xml deleted file mode 100644 index b015098..0000000 --- a/mail_quoted_reply/data/reply_template.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - Reply - Re: ${object.subject} - - - - -
-
- From: ${object.email_from}
- Date: ${object.date}
- Subject: ${object.subject}
- ${object.body | safe} -
- ]]>
-
-
diff --git a/mail_quoted_reply/models/__init__.py b/mail_quoted_reply/models/__init__.py index a2bc21b..a5fceda 100644 --- a/mail_quoted_reply/models/__init__.py +++ b/mail_quoted_reply/models/__init__.py @@ -1 +1,2 @@ from . import mail_message +from . import mail_compose_message diff --git a/mail_quoted_reply/models/mail_compose_message.py b/mail_quoted_reply/models/mail_compose_message.py new file mode 100644 index 0000000..6bb2fa2 --- /dev/null +++ b/mail_quoted_reply/models/mail_compose_message.py @@ -0,0 +1,15 @@ +from markupsafe import Markup + +from odoo import api, models + + +class MailComposeMessage(models.TransientModel): + _inherit = "mail.compose.message" + + @api.onchange("template_id") + def _onchange_template_id_wrapper(self): + super()._onchange_template_id_wrapper() + context = self._context + if "is_quoted_reply" in context.keys() and context["is_quoted_reply"]: + self.body += Markup(context["quote_body"]) + return diff --git a/mail_quoted_reply/models/mail_message.py b/mail_quoted_reply/models/mail_message.py index f1380e4..7adfc54 100644 --- a/mail_quoted_reply/models/mail_message.py +++ b/mail_quoted_reply/models/mail_message.py @@ -8,18 +8,37 @@ class MailMessage(models.Model): _inherit = "mail.message" + def _prep_quoted_reply_body(self): + return """ +
+
+
+
+ From: {email_from}
+ Date: {date}
+ Subject: {subject}
+ {body} +
+ """.format( + email_from=self.email_from, + date=self.date, + subject=self.subject, + body=self.body, + ) + def reply_message(self): action = self.env.ref("mail.action_email_compose_message_wizard").read()[0] action["context"] = { - "default_model": self._name, - "default_res_id": self.id, - "default_template_id": self.env.ref("mail_quoted_reply.reply_template").id, + "default_model": self.model, + "default_res_id": self.res_id, "default_composition_mode": "comment", + "quote_body": self._prep_quoted_reply_body(), "default_is_log": False, "is_log": False, + "is_quoted_reply": True, "default_notify": True, "force_email": True, - "reassign_to_parent": True, "default_partner_ids": [(6, 0, self.partner_ids.ids)], } return action diff --git a/mail_quoted_reply/static/src/components/mail_message_reply.esm.js b/mail_quoted_reply/static/src/components/mail_message_reply.esm.js new file mode 100644 index 0000000..81a7fc2 --- /dev/null +++ b/mail_quoted_reply/static/src/components/mail_message_reply.esm.js @@ -0,0 +1,38 @@ +/** @odoo-module **/ + +import {MessageActionList} from "@mail/components/message_action_list/message_action_list"; +import {patch} from "web.utils"; +import {qweb} from "web.core"; + +const {onMounted} = owl.hooks; + +patch( + MessageActionList.prototype, + "mail_quoted_reply/static/src/components/mail_message_reply.js", + { + xmlDependencies: (MessageActionList.prototype.xmlDependencies || []).concat([ + "/mail_quoted_reply/static/src/xml/mail_message_reply.xml", + ]), + + setup() { + this._super(); + onMounted(() => { + var actionLists = document.querySelectorAll(".o_MessageActionList"); + var MessageQuotedReplyIcon = $( + qweb.render("MessageQuotedReplyButton", this) + )[0]; + if (typeof MessageQuotedReplyIcon !== "undefined") { + MessageQuotedReplyIcon.addEventListener( + "click", + this.messaging.models["mail.message_action_list"].get( + this.props.messageActionListLocalId + ).onClickMailMessageReply + ); + } + actionLists.forEach((actionList) => { + actionList.append(MessageQuotedReplyIcon); + }); + }); + }, + } +); diff --git a/mail_quoted_reply/static/src/components/mail_message_reply.js b/mail_quoted_reply/static/src/components/mail_message_reply.js deleted file mode 100644 index da29add..0000000 --- a/mail_quoted_reply/static/src/components/mail_message_reply.js +++ /dev/null @@ -1,20 +0,0 @@ -odoo.define("mail_quoted_reply/static/src/components/mail_message_reply.js", function ( - require -) { - "use strict"; - - const components = { - Message: require("mail/static/src/components/message/message.js"), - }; - const {patch} = require("web.utils"); - - patch( - components.Message, - "mail_quoted_reply/static/src/models/mail_message_reply.js", - { - _onClickMailMessageReply() { - this.message._onClickMailMessageReply(); - }, - } - ); -}); diff --git a/mail_quoted_reply/static/src/models/mail_message_reply.esm.js b/mail_quoted_reply/static/src/models/mail_message_reply.esm.js new file mode 100644 index 0000000..4017d76 --- /dev/null +++ b/mail_quoted_reply/static/src/models/mail_message_reply.esm.js @@ -0,0 +1,38 @@ +/** @odoo-module **/ + +import {registerInstancePatchModel} from "@mail/model/model_core"; +import rpc from "web.rpc"; + +registerInstancePatchModel( + "mail.message_action_list", + "mail_quoted_reply/static/src/models/mail_message_reply.js", + { + _created() { + this._super(); + this.onClickMailMessageReply = this.onClickMailMessageReply.bind(this); + }, + + /** + * @private + * @param {MouseEvent} ev + */ + onClickMailMessageReply() { + var self = this, + msg_id = this.message.id; + rpc.query({ + model: "mail.message", + method: "reply_message", + args: [msg_id], + }).then(function (result) { + self.env.bus.trigger("do-action", { + action: result, + options: { + on_close: () => { + self.message.originThread.refresh(); + }, + }, + }); + }); + }, + } +); diff --git a/mail_quoted_reply/static/src/models/mail_message_reply.js b/mail_quoted_reply/static/src/models/mail_message_reply.js deleted file mode 100644 index 005c818..0000000 --- a/mail_quoted_reply/static/src/models/mail_message_reply.js +++ /dev/null @@ -1,34 +0,0 @@ -odoo.define("mail_quoted_reply/static/src/models/mail_message_reply.js", function ( - require -) { - "use strict"; - - const {registerInstancePatchModel} = require("mail/static/src/model/model_core.js"); - - registerInstancePatchModel( - "mail.message", - "mail_quoted_reply/static/src/models/mail_message_reply.js", - { - _onClickMailMessageReply: function () { - var self = this, - msg_id = this.id; - this.env.services - .rpc({ - model: "mail.message", - method: "reply_message", - args: [msg_id], - }) - .then(function (result) { - self.env.bus.trigger("do-action", { - action: result, - options: { - on_close: () => { - self.originThread.refresh(); - }, - }, - }); - }); - }, - } - ); -}); diff --git a/mail_quoted_reply/static/src/scss/thread_mail_message_reply.scss b/mail_quoted_reply/static/src/scss/thread_mail_message_reply.scss deleted file mode 100644 index 0d3acbe..0000000 --- a/mail_quoted_reply/static/src/scss/thread_mail_message_reply.scss +++ /dev/null @@ -1,21 +0,0 @@ -.o_thread_mail_message_reply { - cursor: pointer; - color: gray("400"); - &:not(.o-mobile) { - &:hover { - filter: brightness(0.8); - } - } - - &.o-mobile { - filter: brightness(0.8); - - &:hover { - filter: brightness(0.75); - } - } - - &.o-message-selected { - color: gray("500"); - } -} diff --git a/mail_quoted_reply/static/src/xml/mail_message_reply.xml b/mail_quoted_reply/static/src/xml/mail_message_reply.xml index ccf41ab..9f91cd6 100644 --- a/mail_quoted_reply/static/src/xml/mail_message_reply.xml +++ b/mail_quoted_reply/static/src/xml/mail_message_reply.xml @@ -1,19 +1,10 @@ - diff --git a/mail_quoted_reply/templates/assets.xml b/mail_quoted_reply/templates/assets.xml deleted file mode 100644 index 98b0ffd..0000000 --- a/mail_quoted_reply/templates/assets.xml +++ /dev/null @@ -1,28 +0,0 @@ - - - - -