mirror of https://github.com/OCA/social.git
[IMP] mail_gateway: Allow usage of mail templates on gateway
parent
c7b3eee393
commit
34d02e4a39
|
@ -12,6 +12,7 @@
|
||||||
"depends": ["mail"],
|
"depends": ["mail"],
|
||||||
"pre_init_hook": "pre_init_hook",
|
"pre_init_hook": "pre_init_hook",
|
||||||
"data": [
|
"data": [
|
||||||
|
"wizards/mail_compose_gateway_message.xml",
|
||||||
"wizards/mail_message_gateway_link.xml",
|
"wizards/mail_message_gateway_link.xml",
|
||||||
"wizards/mail_message_gateway_send.xml",
|
"wizards/mail_message_gateway_send.xml",
|
||||||
"wizards/mail_guest_manage.xml",
|
"wizards/mail_guest_manage.xml",
|
||||||
|
|
|
@ -66,6 +66,23 @@ class ResPartnerGatewayChannel(models.Model):
|
||||||
"res.company", related="gateway_id.company_id", store=True
|
"res.company", related="gateway_id.company_id", store=True
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def name_get(self):
|
||||||
|
result = []
|
||||||
|
origin = super().name_get()
|
||||||
|
if not self.env.context.get("mail_gateway_partner_info", False):
|
||||||
|
return origin
|
||||||
|
origin_dict = dict(origin)
|
||||||
|
for record in self:
|
||||||
|
result.append(
|
||||||
|
(
|
||||||
|
record.id,
|
||||||
|
"{} ({})".format(
|
||||||
|
record.partner_id.display_name, origin_dict[record.id]
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
_sql_constraints = [
|
_sql_constraints = [
|
||||||
(
|
(
|
||||||
"unique_partner_gateway",
|
"unique_partner_gateway",
|
||||||
|
|
|
@ -7,3 +7,4 @@ access_mail_gateway_all,mail.telegram.bot.all,model_mail_gateway,,1,0,0,0
|
||||||
access_mail_guest_manage,mail.telegram.bot.all,model_mail_guest_manage,base.group_user,1,1,1,1
|
access_mail_guest_manage,mail.telegram.bot.all,model_mail_guest_manage,base.group_user,1,1,1,1
|
||||||
access_mail_message_gateway_link,mail.message.link.all,model_mail_message_gateway_link,base.group_user,1,1,1,1
|
access_mail_message_gateway_link,mail.message.link.all,model_mail_message_gateway_link,base.group_user,1,1,1,1
|
||||||
access_mail_gateway_system,mail_gateway,model_mail_gateway,base.group_system,1,1,1,1
|
access_mail_gateway_system,mail_gateway,model_mail_gateway,base.group_system,1,1,1,1
|
||||||
|
access_mail_compose_gateway_message,access.mail.compose.gateway.message,model_mail_compose_gateway_message,base.group_user,1,1,1,0
|
||||||
|
|
|
|
@ -1,6 +1,7 @@
|
||||||
/** @odoo-module **/
|
/** @odoo-module **/
|
||||||
|
|
||||||
import {clear} from "@mail/model/model_field_command";
|
import {clear} from "@mail/model/model_field_command";
|
||||||
|
import {escapeAndCompactTextContent} from "@mail/js/utils";
|
||||||
import {one} from "@mail/model/model_field";
|
import {one} from "@mail/model/model_field";
|
||||||
import {registerPatch} from "@mail/model/model_core";
|
import {registerPatch} from "@mail/model/model_core";
|
||||||
|
|
||||||
|
@ -17,6 +18,63 @@ registerPatch({
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
async openFullComposer() {
|
||||||
|
if (this.composer.isGateway) {
|
||||||
|
const attachmentIds = this.composer.attachments.map(
|
||||||
|
(attachment) => attachment.id
|
||||||
|
);
|
||||||
|
const context = {
|
||||||
|
default_attachment_ids: attachmentIds,
|
||||||
|
default_body: escapeAndCompactTextContent(
|
||||||
|
this.composer.textInputContent
|
||||||
|
),
|
||||||
|
default_model: this.composer.activeThread.model,
|
||||||
|
default_partner_ids: this.composer.recipients.map(
|
||||||
|
(partner) => partner.id
|
||||||
|
),
|
||||||
|
default_res_id: this.composer.activeThread.id,
|
||||||
|
mail_post_autofollow: this.composer.activeThread.hasWriteAccess,
|
||||||
|
default_wizard_partner_ids: Array.from(
|
||||||
|
new Set(
|
||||||
|
this.composer.composerGatewayFollowers.map((follower) => {
|
||||||
|
return follower.follower.partner.id;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
),
|
||||||
|
default_wizard_channel_ids: Array.from(
|
||||||
|
new Set(
|
||||||
|
this.composer.composerGatewayFollowers.map((follower) => {
|
||||||
|
return follower.channel;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
),
|
||||||
|
};
|
||||||
|
const action = {
|
||||||
|
type: "ir.actions.act_window",
|
||||||
|
name: this.env._t("Gateway message"),
|
||||||
|
res_model: "mail.compose.gateway.message",
|
||||||
|
view_mode: "form",
|
||||||
|
views: [[false, "form"]],
|
||||||
|
target: "new",
|
||||||
|
context: context,
|
||||||
|
};
|
||||||
|
const composer = this.composer;
|
||||||
|
const options = {
|
||||||
|
onClose: () => {
|
||||||
|
if (!composer.exists()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
composer._reset();
|
||||||
|
if (composer.activeThread) {
|
||||||
|
composer.activeThread.fetchData(["messages"]);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
};
|
||||||
|
await this.env.services.action.doAction(action, options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
return await this._super(...arguments);
|
||||||
|
},
|
||||||
},
|
},
|
||||||
fields: {
|
fields: {
|
||||||
hasFollowers: {
|
hasFollowers: {
|
||||||
|
@ -32,17 +90,6 @@ registerPatch({
|
||||||
return Boolean(this._super() || this.composer.isGateway);
|
return Boolean(this._super() || this.composer.isGateway);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
isExpandable: {
|
|
||||||
/*
|
|
||||||
We will not allow to expand on this composer due to all complexity of selection
|
|
||||||
*/
|
|
||||||
compute() {
|
|
||||||
if (this.composer.isGateway) {
|
|
||||||
return clear();
|
|
||||||
}
|
|
||||||
return this._super();
|
|
||||||
},
|
|
||||||
},
|
|
||||||
composerGatewayChannelView: one("GatewayChannelView", {
|
composerGatewayChannelView: one("GatewayChannelView", {
|
||||||
compute() {
|
compute() {
|
||||||
if (this.composer.isGateway) {
|
if (this.composer.isGateway) {
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
from . import mail_guest_manage
|
from . import mail_guest_manage
|
||||||
from . import mail_message_gateway_send
|
from . import mail_message_gateway_send
|
||||||
from . import mail_message_gateway_link
|
from . import mail_message_gateway_link
|
||||||
|
from . import mail_compose_gateway_message
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
# Copyright 2024 Dixmit
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from odoo import fields, models
|
||||||
|
|
||||||
|
|
||||||
|
class MailComposeGatewayMessage(models.TransientModel):
|
||||||
|
_name = "mail.compose.gateway.message"
|
||||||
|
_inherit = "mail.compose.message"
|
||||||
|
_description = "Mail Compose Gateway Message"
|
||||||
|
|
||||||
|
wizard_partner_ids = fields.Many2many(
|
||||||
|
"res.partner",
|
||||||
|
"mail_compose_gateway_message_res_partner_rel",
|
||||||
|
"wizard_id",
|
||||||
|
"partner_id",
|
||||||
|
)
|
||||||
|
wizard_channel_ids = fields.Many2many(
|
||||||
|
"res.partner.gateway.channel",
|
||||||
|
"mail_compose_gateway_message_gateway_channel_rel",
|
||||||
|
"wizard_id",
|
||||||
|
"channel_id",
|
||||||
|
)
|
||||||
|
attachment_ids = fields.Many2many(
|
||||||
|
"ir.attachment",
|
||||||
|
"mail_compose_gateway_message_ir_attachments_rel",
|
||||||
|
"wizard_id",
|
||||||
|
"attachment_id",
|
||||||
|
"Attachments",
|
||||||
|
)
|
||||||
|
|
||||||
|
partner_ids = fields.Many2many(
|
||||||
|
"res.partner",
|
||||||
|
"mail_compose_gateway_message_res_partner_rel",
|
||||||
|
"wizard_id",
|
||||||
|
"partner_id",
|
||||||
|
"Additional Contacts",
|
||||||
|
domain=lambda r: r._partner_ids_domain(),
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_mail_values(self, res_ids):
|
||||||
|
self.ensure_one()
|
||||||
|
res = super(MailComposeGatewayMessage, self).get_mail_values(res_ids)
|
||||||
|
res[res_ids[0]]["gateway_notifications"] = [
|
||||||
|
{
|
||||||
|
"partner_id": channel.partner_id.id,
|
||||||
|
"channel_type": "gateway",
|
||||||
|
"gateway_channel_id": channel.id,
|
||||||
|
}
|
||||||
|
for channel in self.wizard_channel_ids
|
||||||
|
]
|
||||||
|
return res
|
|
@ -0,0 +1,39 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<!-- Copyright 2024 Dixmit
|
||||||
|
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
|
||||||
|
<odoo>
|
||||||
|
|
||||||
|
<record model="ir.ui.view" id="mail_compose_gateway_message_form_view">
|
||||||
|
<field name="model">mail.compose.gateway.message</field>
|
||||||
|
<field name="inherit_id" ref="mail.email_compose_message_wizard_form" />
|
||||||
|
<field name="mode">primary</field>
|
||||||
|
<field name="arch" type="xml">
|
||||||
|
<field name="partner_ids" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
</field>
|
||||||
|
<field name="body" position="before">
|
||||||
|
<field name="wizard_partner_ids" invisible="1" />
|
||||||
|
<field
|
||||||
|
name="wizard_channel_ids"
|
||||||
|
widget="many2many_tags"
|
||||||
|
context="{'mail_gateway_partner_info': 1}"
|
||||||
|
domain="[('partner_id', 'in', wizard_partner_ids)]"
|
||||||
|
/>
|
||||||
|
</field>
|
||||||
|
<field name="subject" position="attributes">
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
<attribute name="required">0</attribute>
|
||||||
|
</field>
|
||||||
|
<xpath
|
||||||
|
expr="//span[@name='document_followers_text']/.."
|
||||||
|
position="attributes"
|
||||||
|
>
|
||||||
|
<attribute name="invisible">1</attribute>
|
||||||
|
<attribute name="attrs" />
|
||||||
|
</xpath>
|
||||||
|
</field>
|
||||||
|
</record>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</odoo>
|
Loading…
Reference in New Issue