Skip to content

Commit

Permalink
Merge PR #1489 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by pedrobaeza
  • Loading branch information
OCA-git-bot committed Nov 8, 2024
2 parents c7b3eee + 8b6e6c4 commit 36c38a8
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 11 deletions.
1 change: 1 addition & 0 deletions mail_gateway/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"depends": ["mail"],
"pre_init_hook": "pre_init_hook",
"data": [
"wizards/mail_compose_gateway_message.xml",
"wizards/mail_message_gateway_link.xml",
"wizards/mail_message_gateway_send.xml",
"wizards/mail_guest_manage.xml",
Expand Down
19 changes: 19 additions & 0 deletions mail_gateway/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ class ResPartnerGatewayChannel(models.Model):
"res.company", related="gateway_id.company_id", store=True
)

def name_get(self):
# Be able to tell to which partner belongs the gateway partner channel
# e.g.: picking it from a selector
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 = [
(
"unique_partner_gateway",
Expand Down
1 change: 1 addition & 0 deletions mail_gateway/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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_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_compose_gateway_message,access.mail.compose.gateway.message,model_mail_compose_gateway_message,base.group_user,1,1,1,0
69 changes: 58 additions & 11 deletions mail_gateway/static/src/models/composer_view.esm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @odoo-module **/

import {clear} from "@mail/model/model_field_command";
import {escapeAndCompactTextContent} from "@mail/js/utils";
import {one} from "@mail/model/model_field";
import {registerPatch} from "@mail/model/model_core";

Expand All @@ -17,6 +18,63 @@ registerPatch({
}
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: {
hasFollowers: {
Expand All @@ -32,17 +90,6 @@ registerPatch({
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", {
compute() {
if (this.composer.isGateway) {
Expand Down
1 change: 1 addition & 0 deletions mail_gateway/wizards/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import mail_guest_manage
from . import mail_message_gateway_send
from . import mail_message_gateway_link
from . import mail_compose_gateway_message
75 changes: 75 additions & 0 deletions mail_gateway/wizards/mail_compose_gateway_message.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# 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(),
)
# Dummy compatibility with other OCA modules
# OCA/mail_attach_existing_attachment
object_attachment_ids = fields.Many2many(
comodel_name="ir.attachment",
relation="mail_compose_gateway_message_ir_attachments_object_rel",
column1="wizard_id",
column2="attachment_id",
string="Object Attachments",
)
# OCA/mail_composer_cc_bcc
partner_cc_ids = fields.Many2many(
comodel_name="res.partner",
relation="mail_compose_gateway_message_res_partner_cc_rel",
column1="wizard_id",
column2="partner_id",
string="Cc",
)
partner_bcc_ids = fields.Many2many(
comodel_name="res.partner",
relation="mail_compose_gateway_message_res_partner_bcc_rel",
column1="wizard_id",
column2="partner_id",
string="Bcc",
)

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
43 changes: 43 additions & 0 deletions mail_gateway/wizards/mail_compose_gateway_message.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?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">
<label for="partner_ids" position="attributes">
<attribute name="invisible">1</attribute>
</label>
<field name="partner_ids" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="subject" position="before">
<field name="wizard_partner_ids" invisible="1" />
<field
name="wizard_channel_ids"
string="Gateways"
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>

0 comments on commit 36c38a8

Please sign in to comment.