Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][IMP] mail_gateway: Allow to use expand on Gateway messages #1443

Open
wants to merge 2 commits into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions mail_gateway/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,23 @@ class ResPartnerGatewayChannel(models.Model):
"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 = [
(
"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
11 changes: 7 additions & 4 deletions mail_gateway/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -274,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -300,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -428,7 +429,9 @@ <h2><a class="toc-backref" href="#toc-entry-6">Other credits</a></h2>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
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
52 changes: 52 additions & 0 deletions mail_gateway/wizards/mail_compose_gateway_message.py
Original file line number Diff line number Diff line change
@@ -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
39 changes: 39 additions & 0 deletions mail_gateway/wizards/mail_compose_gateway_message.xml
Original file line number Diff line number Diff line change
@@ -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