summaryrefslogtreecommitdiff
path: root/addons/website_livechat/models/im_livechat_channel.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/website_livechat/models/im_livechat_channel.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/website_livechat/models/im_livechat_channel.py')
-rw-r--r--addons/website_livechat/models/im_livechat_channel.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/addons/website_livechat/models/im_livechat_channel.py b/addons/website_livechat/models/im_livechat_channel.py
new file mode 100644
index 00000000..fe4b46b0
--- /dev/null
+++ b/addons/website_livechat/models/im_livechat_channel.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import models, _
+
+
+class ImLivechatChannel(models.Model):
+ _inherit = 'im_livechat.channel'
+
+ def _get_livechat_mail_channel_vals(self, anonymous_name, operator, user_id=None, country_id=None):
+ mail_channel_vals = super(ImLivechatChannel, self)._get_livechat_mail_channel_vals(anonymous_name, operator, user_id=user_id, country_id=country_id)
+ visitor_sudo = self.env['website.visitor']._get_visitor_from_request()
+ if visitor_sudo:
+ mail_channel_vals['livechat_visitor_id'] = visitor_sudo.id
+ if not user_id:
+ mail_channel_vals['anonymous_name'] = visitor_sudo.display_name + (' (%s)' % visitor_sudo.country_id.name if visitor_sudo.country_id else '')
+ # As chat requested by the visitor, delete the chat requested by an operator if any to avoid conflicts between two flows
+ # TODO DBE : Move this into the proper method (open or init mail channel)
+ chat_request_channel = self.env['mail.channel'].sudo().search([('livechat_visitor_id', '=', visitor_sudo.id), ('livechat_active', '=', True)])
+ for mail_channel in chat_request_channel:
+ mail_channel._close_livechat_session(cancel=True, operator=operator.name)
+
+ return mail_channel_vals