From f3cddb4d8f966e33e7cc2123698e223edaf89e63 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Thu, 12 Sep 2024 15:49:58 +0200 Subject: [PATCH 1/2] [IMP] mail_gateway: Allow usage of mail templates on gateway --- mail_gateway/__manifest__.py | 1 + mail_gateway/security/ir.model.access.csv | 2 + mail_gateway/static/description/index.html | 11 ++-- .../static/src/models/composer_view.esm.js | 61 +++++++++++++++---- mail_gateway/wizards/__init__.py | 1 + .../wizards/mail_compose_gateway_message.py | 54 ++++++++++++++++ .../wizards/mail_compose_gateway_message.xml | 47 ++++++++++++++ 7 files changed, 162 insertions(+), 15 deletions(-) create mode 100644 mail_gateway/wizards/mail_compose_gateway_message.py create mode 100644 mail_gateway/wizards/mail_compose_gateway_message.xml diff --git a/mail_gateway/__manifest__.py b/mail_gateway/__manifest__.py index 426380b7d8..a6a7ab16fa 100644 --- a/mail_gateway/__manifest__.py +++ b/mail_gateway/__manifest__.py @@ -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", diff --git a/mail_gateway/security/ir.model.access.csv b/mail_gateway/security/ir.model.access.csv index 76c24d0cf2..4e8643e59f 100644 --- a/mail_gateway/security/ir.model.access.csv +++ b/mail_gateway/security/ir.model.access.csv @@ -7,3 +7,5 @@ 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 +access_mail_compose_gateway_message_partner,access.mail.compose.gateway.message.partner,model_mail_compose_gateway_message_partner,base.group_user,1,1,1,0 diff --git a/mail_gateway/static/description/index.html b/mail_gateway/static/description/index.html index d881070843..0b01d9e269 100644 --- a/mail_gateway/static/description/index.html +++ b/mail_gateway/static/description/index.html @@ -8,10 +8,11 @@ /* :Author: David Goodger (goodger@python.org) -: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. @@ -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 } @@ -300,7 +301,7 @@ span.pre { white-space: pre } -span.problematic { +span.problematic, pre.problematic { color: red } span.section-subtitle { @@ -428,7 +429,9 @@

Other credits

Maintainers

This module is maintained by the OCA.

-Odoo Community Association + +Odoo Community Association +

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.

diff --git a/mail_gateway/static/src/models/composer_view.esm.js b/mail_gateway/static/src/models/composer_view.esm.js index 60c8a20f63..00c38c43fe 100644 --- a/mail_gateway/static/src/models/composer_view.esm.js +++ b/mail_gateway/static/src/models/composer_view.esm.js @@ -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"; @@ -17,6 +18,55 @@ registerPatch({ } return result; }, + async openFullComposer() { + if (this.composer.isGateway) { + const attachmentIds = this.composer.attachments.map( + (attachment) => attachment.id + ); + console.log(this); + 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: + this.composer.composerGatewayFollowers.map((follower) => { + return follower._getMessageData(); + }), + }; + console.log(context); + 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: { @@ -32,17 +82,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) { diff --git a/mail_gateway/wizards/__init__.py b/mail_gateway/wizards/__init__.py index 2f4b9a9e34..070ca5631c 100644 --- a/mail_gateway/wizards/__init__.py +++ b/mail_gateway/wizards/__init__.py @@ -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 diff --git a/mail_gateway/wizards/mail_compose_gateway_message.py b/mail_gateway/wizards/mail_compose_gateway_message.py new file mode 100644 index 0000000000..8e49c92e86 --- /dev/null +++ b/mail_gateway/wizards/mail_compose_gateway_message.py @@ -0,0 +1,54 @@ +# 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.One2many( + "mail.compose.gateway.message.partner", "wizard_id", "Recipents" + ) + 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": partner.partner_id.id, + "channel_type": partner.channel_type, + "gateway_channel_id": partner.gateway_channel_id.id, + } + for partner in self.wizard_partner_ids + ] + return res + + +class MailComposeGatewayMessagePartner(models.TransientModel): + _name = "mail.compose.gateway.message.partner" + + wizard_id = fields.Many2one( + "mail.compose.gateway.message", "Wizard", required=True, ondelete="cascade" + ) + partner_id = fields.Many2one("res.partner", "Contact", required=True, readonly=True) + gateway_channel_id = fields.Many2one("res.partner.gateway.channel", "Channel") + channel_type = fields.Char() diff --git a/mail_gateway/wizards/mail_compose_gateway_message.xml b/mail_gateway/wizards/mail_compose_gateway_message.xml new file mode 100644 index 0000000000..c22adb86ab --- /dev/null +++ b/mail_gateway/wizards/mail_compose_gateway_message.xml @@ -0,0 +1,47 @@ + + + + + + mail.compose.gateway.message + + primary + + + 1 + + + + + + + + + + + + 1 + 0 + + + 1 + + + + + + + + From ebd50f5c2a12f19446264d090ab47e6739fd7585 Mon Sep 17 00:00:00 2001 From: Enric Tobella Date: Thu, 12 Sep 2024 16:42:15 +0200 Subject: [PATCH 2/2] fixup! [IMP] mail_gateway: Allow usage of mail templates on gateway --- mail_gateway/models/res_partner.py | 17 ++++++++++ mail_gateway/security/ir.model.access.csv | 1 - .../static/src/models/composer_view.esm.js | 20 ++++++++---- .../wizards/mail_compose_gateway_message.py | 32 +++++++++---------- .../wizards/mail_compose_gateway_message.xml | 22 ++++--------- 5 files changed, 53 insertions(+), 39 deletions(-) diff --git a/mail_gateway/models/res_partner.py b/mail_gateway/models/res_partner.py index a43e9e69c4..5a2e3db5ef 100644 --- a/mail_gateway/models/res_partner.py +++ b/mail_gateway/models/res_partner.py @@ -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", diff --git a/mail_gateway/security/ir.model.access.csv b/mail_gateway/security/ir.model.access.csv index 4e8643e59f..afa35f6aa1 100644 --- a/mail_gateway/security/ir.model.access.csv +++ b/mail_gateway/security/ir.model.access.csv @@ -8,4 +8,3 @@ access_mail_guest_manage,mail.telegram.bot.all,model_mail_guest_manage,base.grou 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 -access_mail_compose_gateway_message_partner,access.mail.compose.gateway.message.partner,model_mail_compose_gateway_message_partner,base.group_user,1,1,1,0 diff --git a/mail_gateway/static/src/models/composer_view.esm.js b/mail_gateway/static/src/models/composer_view.esm.js index 00c38c43fe..dfb481ab02 100644 --- a/mail_gateway/static/src/models/composer_view.esm.js +++ b/mail_gateway/static/src/models/composer_view.esm.js @@ -23,7 +23,6 @@ registerPatch({ const attachmentIds = this.composer.attachments.map( (attachment) => attachment.id ); - console.log(this); const context = { default_attachment_ids: attachmentIds, default_body: escapeAndCompactTextContent( @@ -35,12 +34,21 @@ registerPatch({ ), default_res_id: this.composer.activeThread.id, mail_post_autofollow: this.composer.activeThread.hasWriteAccess, - default_wizard_partner_ids: - this.composer.composerGatewayFollowers.map((follower) => { - return follower._getMessageData(); - }), + 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; + }) + ) + ), }; - console.log(context); const action = { type: "ir.actions.act_window", name: this.env._t("Gateway message"), diff --git a/mail_gateway/wizards/mail_compose_gateway_message.py b/mail_gateway/wizards/mail_compose_gateway_message.py index 8e49c92e86..483a7598c2 100644 --- a/mail_gateway/wizards/mail_compose_gateway_message.py +++ b/mail_gateway/wizards/mail_compose_gateway_message.py @@ -9,8 +9,17 @@ class MailComposeGatewayMessage(models.TransientModel): _inherit = "mail.compose.message" _description = "Mail Compose Gateway Message" - wizard_partner_ids = fields.One2many( - "mail.compose.gateway.message.partner", "wizard_id", "Recipents" + 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", @@ -34,21 +43,10 @@ def get_mail_values(self, res_ids): res = super(MailComposeGatewayMessage, self).get_mail_values(res_ids) res[res_ids[0]]["gateway_notifications"] = [ { - "partner_id": partner.partner_id.id, - "channel_type": partner.channel_type, - "gateway_channel_id": partner.gateway_channel_id.id, + "partner_id": channel.partner_id.id, + "channel_type": "gateway", + "gateway_channel_id": channel.id, } - for partner in self.wizard_partner_ids + for channel in self.wizard_channel_ids ] return res - - -class MailComposeGatewayMessagePartner(models.TransientModel): - _name = "mail.compose.gateway.message.partner" - - wizard_id = fields.Many2one( - "mail.compose.gateway.message", "Wizard", required=True, ondelete="cascade" - ) - partner_id = fields.Many2one("res.partner", "Contact", required=True, readonly=True) - gateway_channel_id = fields.Many2one("res.partner.gateway.channel", "Channel") - channel_type = fields.Char() diff --git a/mail_gateway/wizards/mail_compose_gateway_message.xml b/mail_gateway/wizards/mail_compose_gateway_message.xml index c22adb86ab..895f512ce2 100644 --- a/mail_gateway/wizards/mail_compose_gateway_message.xml +++ b/mail_gateway/wizards/mail_compose_gateway_message.xml @@ -12,21 +12,13 @@ 1 - - - - - - - + + 1