diff --git a/mail_gateway/__manifest__.py b/mail_gateway/__manifest__.py index fdc88ac8dc..b8711f43e9 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/models/res_partner.py b/mail_gateway/models/res_partner.py index a43e9e69c4..57f5e03aeb 100644 --- a/mail_gateway/models/res_partner.py +++ b/mail_gateway/models/res_partner.py @@ -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", diff --git a/mail_gateway/security/ir.model.access.csv b/mail_gateway/security/ir.model.access.csv index 76c24d0cf2..afa35f6aa1 100644 --- a/mail_gateway/security/ir.model.access.csv +++ b/mail_gateway/security/ir.model.access.csv @@ -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 diff --git a/mail_gateway/static/src/models/composer_view.esm.js b/mail_gateway/static/src/models/composer_view.esm.js index 60c8a20f63..dfb481ab02 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,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: { @@ -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) { 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..45e7192329 --- /dev/null +++ b/mail_gateway/wizards/mail_compose_gateway_message.py @@ -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 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..37e741485d --- /dev/null +++ b/mail_gateway/wizards/mail_compose_gateway_message.xml @@ -0,0 +1,43 @@ + + + + + + mail.compose.gateway.message + + primary + + + + 1 + + + + + + + 1 + 0 + + + 1 + + + + + + + +