Skip to content

Commit

Permalink
fixup! [IMP] mail_gateway: Allow usage of mail templates on gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
etobella committed Sep 12, 2024
1 parent f3cddb4 commit ebd50f5
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 39 deletions.
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: 0 additions & 1 deletion mail_gateway/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 14 additions & 6 deletions mail_gateway/static/src/models/composer_view.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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"),
Expand Down
32 changes: 15 additions & 17 deletions mail_gateway/wizards/mail_compose_gateway_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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()
22 changes: 7 additions & 15 deletions mail_gateway/wizards/mail_compose_gateway_message.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,13 @@
<attribute name="invisible">1</attribute>
</field>
<field name="body" position="before">
<field name="wizard_partner_ids">
<tree create="0" editable="bottom">
<field
name="partner_id"
options="{'no_create': True, 'no_open': True}"
force_save="1"
/>
<field
name="gateway_channel_id"
domain="[('partner_id', '=', partner_id)]"
options="{'no_open': 1, 'no_create': 1}"
/>
<field name="channel_type" invisible="1" />
</tree>
</field>
<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>
Expand Down

0 comments on commit ebd50f5

Please sign in to comment.