Skip to content

Commit 1825142

Browse files
committed
[MIG] mail_gateway: Migratio to 17.0
1 parent 347ddec commit 1825142

File tree

10 files changed

+28
-23
lines changed

10 files changed

+28
-23
lines changed

mail_gateway/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "Mail Gateway",
66
"summary": """
77
Set a gateway""",
8-
"version": "16.0.1.0.0",
8+
"version": "17.0.1.0.0",
99
"license": "AGPL-3",
1010
"author": "Creu Blanca,Dixmit,Odoo Community Association (OCA)",
1111
"website": "https://github.com/OCA/social",

mail_gateway/controllers/discuss.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Copyright 2024 Dixmit
22
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
33

4-
from odoo.addons.mail.controllers.discuss import DiscussController
4+
from odoo.addons.mail.controllers.thread import ThreadController
55

66

7-
class GatewayDiscussController(DiscussController):
7+
class GatewayThreadController(ThreadController):
88
def _get_allowed_message_post_params(self):
99
result = super()._get_allowed_message_post_params()
1010
result.add("gateway_notifications")

mail_gateway/hooks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
def pre_init_hook(cr):
1+
def pre_init_hook(env):
22
"""
33
The objective of this hook is to speed up the installation
44
of the module on an existing Odoo instance.
55
66
Without this script, big databases can take a long time to install this
77
module.
88
"""
9-
cr.execute(
9+
env.cr.execute(
1010
"""ALTER TABLE mail_message
1111
ADD COLUMN gateway_channel_id int"""
1212
)

mail_gateway/models/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
from . import mail_gateway_abstract
99
from . import res_users
1010
from . import mail_thread
11+
12+
from . import discuss
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import discuss_channel

mail_gateway/models/mail_channel.py renamed to mail_gateway/models/discuss/discuss_channel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
class MailChannel(models.Model):
10-
_inherit = "mail.channel"
10+
_inherit = "discuss.channel"
1111

1212
gateway_channel_token = fields.Char()
1313
anonymous_name = fields.Char() # Same field we will use on im_livechat
@@ -26,9 +26,9 @@ class MailChannel(models.Model):
2626
required=False,
2727
)
2828

29-
def channel_info(self):
30-
result = super().channel_info()
31-
for record, item in zip(self, result):
29+
def _channel_info(self):
30+
result = super()._channel_info()
31+
for record, item in zip(self, result, strict=True):
3232
item["gateway"] = {
3333
"id": record.gateway_id.id,
3434
"name": record.gateway_id.name,

mail_gateway/models/mail_gateway.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def _get_channel_id(self, chat_token):
6363
)
6464

6565
def _get_webhook_url(self):
66-
return "%s/gateway/%s/%s/update" % (
66+
return "{}/gateway/{}/{}/update".format(
6767
self.webhook_url
6868
or self.env["ir.config_parameter"].get_param("web.base.url"),
6969
self.gateway_type,
@@ -93,7 +93,7 @@ def update_webhook(self):
9393
self.set_webhook()
9494

9595
def write(self, vals):
96-
res = super(MailGateway, self).write(vals)
96+
res = super().write(vals)
9797
if (
9898
"webhook_key" in vals
9999
or "integrated_webhook_state" in vals
@@ -105,7 +105,7 @@ def write(self, vals):
105105

106106
@api.model_create_multi
107107
def create(self, mvals):
108-
res = super(MailGateway, self).create(mvals)
108+
res = super().create(mvals)
109109
self.clear_caches()
110110
return res
111111

mail_gateway/models/mail_message.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,18 @@ def _compute_gateway_thread_data(self):
4848
def _compute_gateway_channel_ids(self):
4949
for record in self:
5050
if self.env.user.has_group("mail_gateway.gateway_user"):
51-
channels = record.notification_ids.res_partner_id.gateway_channel_ids.filtered(
52-
lambda r: (r.gateway_token, r.gateway_id.id)
51+
partners = record.notification_ids.res_partner_id
52+
channels = partners.gateway_channel_ids.filtered(
53+
lambda r, messages=record.gateway_message_ids: (
54+
r.gateway_token,
55+
r.gateway_id.id,
56+
)
5357
not in [
5458
(
5559
notification.gateway_channel_id.gateway_channel_token,
5660
notification.gateway_channel_id.gateway_id.id,
5761
)
58-
for notification in record.gateway_message_ids.gateway_notification_ids
62+
for notification in messages.gateway_notification_ids
5963
]
6064
)
6165
else:
@@ -76,9 +80,7 @@ def _compute_gateway_channel_id(self):
7680

7781
def _get_message_format_fields(self):
7882
result = super()._get_message_format_fields()
79-
result.append("gateway_type")
80-
result.append("gateway_channel_data")
81-
result.append("gateway_thread_data")
83+
result += ["gateway_type", "gateway_channel_data", "gateway_thread_data"]
8284
return result
8385

8486
def _send_to_gateway_thread(self, gateway_channel_id):

mail_gateway/models/mail_notification.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def _set_read_gateway(self):
2626

2727
def _notification_format(self):
2828
result = super()._notification_format()
29-
for record, formatted_value in zip(self, result):
29+
for record, formatted_value in zip(self, result, strict=True):
3030
formatted_value["gateway_type"] = record.gateway_type
3131
formatted_value["channel_name"] = record.gateway_channel_id.name
3232
return result

mail_gateway/models/mail_thread.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ def _message_update_content(
7272
)
7373
if body == "":
7474
# Unlink the message
75-
for gateway_message in message.gateway_message_ids:
76-
gateway_message.gateway_message_id = False
75+
for gateway_msg in message.gateway_message_ids:
76+
gateway_msg.gateway_message_id = False
7777
self.env["bus.bus"]._sendone(
7878
self.env.user.partner_id,
7979
"mail.message/insert",
8080
{
81-
"id": gateway_message.id,
82-
"gateway_thread_data": gateway_message.sudo().gateway_thread_data,
81+
"id": gateway_msg.id,
82+
"gateway_thread_data": gateway_msg.sudo().gateway_thread_data,
8383
},
8484
)
8585
return result

0 commit comments

Comments
 (0)