[MIG] mail_quoted_reply: Migration to 15.0
This commit is contained in:
parent
0eb189f1c4
commit
59ef84c8ec
@ -1,2 +1 @@
|
||||
from . import models
|
||||
from . import wizards
|
||||
|
@ -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",
|
||||
],
|
||||
},
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="reply_template" model="mail.template">
|
||||
<field name="name">Reply</field>
|
||||
<field name="subject">Re: ${object.subject}</field>
|
||||
<field name="use_default_to" eval="True" />
|
||||
<field name="model_id" ref="mail.model_mail_message" />
|
||||
<field
|
||||
name="body_html"
|
||||
><![CDATA[
|
||||
<div>
|
||||
</div>
|
||||
<br/>
|
||||
<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">
|
||||
From: ${object.email_from}<br/>
|
||||
Date: ${object.date}<br/>
|
||||
Subject: ${object.subject}<br/>
|
||||
${object.body | safe}
|
||||
</blockquote>
|
||||
]]></field>
|
||||
</record>
|
||||
</odoo>
|
@ -1 +1,2 @@
|
||||
from . import mail_message
|
||||
from . import mail_compose_message
|
||||
|
15
mail_quoted_reply/models/mail_compose_message.py
Normal file
15
mail_quoted_reply/models/mail_compose_message.py
Normal file
@ -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
|
@ -8,18 +8,37 @@ class MailMessage(models.Model):
|
||||
|
||||
_inherit = "mail.message"
|
||||
|
||||
def _prep_quoted_reply_body(self):
|
||||
return """
|
||||
<div>
|
||||
</div>
|
||||
<br/>
|
||||
<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">
|
||||
From: {email_from}<br/>
|
||||
Date: {date}<br/>
|
||||
Subject: {subject}<br/>
|
||||
{body}
|
||||
</blockquote>
|
||||
""".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
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
@ -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();
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
@ -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();
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
@ -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();
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
},
|
||||
}
|
||||
);
|
||||
});
|
@ -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");
|
||||
}
|
||||
}
|
@ -1,19 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!-- Copyright 2021 Creu Blanca
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<template>
|
||||
<t t-inherit="mail.Message" t-inherit-mode="extension">
|
||||
<xpath
|
||||
expr="//div[hasclass('o_Message_core')]//div[hasclass('o_Message_headerCommands')]/t[1]"
|
||||
position="inside"
|
||||
>
|
||||
<t>
|
||||
<span
|
||||
class="fa fa-reply o_thread_icon o_thread_mail_message_reply"
|
||||
t-on-click="_onClickMailMessageReply"
|
||||
title="Reply"
|
||||
/>
|
||||
</t>
|
||||
</xpath>
|
||||
<t t-name="MessageQuotedReplyButton">
|
||||
<span
|
||||
class="p-2 fa fa-lg fa-reply o_MessageActionList_action"
|
||||
t-on-click="_onClickMailMessageReply"
|
||||
title="Reply"
|
||||
/>
|
||||
</t>
|
||||
</template>
|
||||
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<!-- Copyright 2014-2015 Grupo ESOC <http://www.grupoesoc.es>
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). -->
|
||||
<odoo>
|
||||
|
||||
<template
|
||||
id="assets_backend"
|
||||
name="mail_quoted_reply assets"
|
||||
inherit_id="web.assets_backend"
|
||||
>
|
||||
<xpath expr="." position="inside">
|
||||
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/mail_quoted_reply/static/src/components/mail_message_reply.js"
|
||||
/>
|
||||
<script
|
||||
type="text/javascript"
|
||||
src="/mail_quoted_reply/static/src/models/mail_message_reply.js"
|
||||
/>
|
||||
<link
|
||||
href="/mail_quoted_reply/static/src/scss/thread_mail_message_reply.scss"
|
||||
rel="stylesheet"
|
||||
type="text/scss"
|
||||
/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
@ -1,6 +1,8 @@
|
||||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
import re
|
||||
|
||||
from odoo.tests import TransactionCase
|
||||
|
||||
|
||||
@ -24,8 +26,12 @@ class TestMessageReply(TransactionCase):
|
||||
)
|
||||
action = message.reply_message()
|
||||
wizard = (
|
||||
self.env[action["res_model"]].with_context(action["context"]).create({})
|
||||
self.env[action["res_model"]].with_context(**action["context"]).create({})
|
||||
)
|
||||
# the onchange in the composer isn't triggered in tests, so we check for the
|
||||
# correct quote in the context
|
||||
email_quote = re.search("<p>.*?</p>", wizard._context["quote_body"]).group()
|
||||
self.assertEqual("<p>demo message</p>", email_quote)
|
||||
wizard.action_send_mail()
|
||||
new_message = partner.message_ids.filtered(
|
||||
lambda r: r.message_type != "notification" and r != message
|
||||
|
@ -1 +0,0 @@
|
||||
from . import mail_compose_message_reply
|
@ -1,19 +0,0 @@
|
||||
# Copyright 2021 Creu Blanca
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
|
||||
from odoo import models
|
||||
|
||||
|
||||
class MailComposeMessageReply(models.TransientModel):
|
||||
|
||||
_inherit = "mail.compose.message"
|
||||
|
||||
def send_mail(self, auto_commit=False):
|
||||
if self.env.context.get("reassign_to_parent"):
|
||||
for record in self:
|
||||
if record.model == "mail.message":
|
||||
parent = self.env[record.model].browse(record.res_id)
|
||||
record.model = parent.model
|
||||
record.res_id = parent.res_id
|
||||
record.parent_id = parent
|
||||
return super().send_mail(auto_commit=auto_commit)
|
Loading…
Reference in New Issue
Block a user