summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2021-02-15 13:51:19 +0000
committerDavid Beguin <dbe@odoo.com>2021-04-16 10:55:54 +0000
commit4e1034ff2f08fa20bcdc9ac39eb2489d34a9715d (patch)
tree9a2e07e7840793d9d75731eb566481c327090eb9 /addons
parent2692dab7ff943082ba3c92a8514e7b69b9ad6843 (diff)
[FIX] website_livechat: ensure session data integrity during visitor lifecycle
This commit fixes two issues encountered during the visitor lifecycle. 1. When a visitor arrives on the website on a non tracked page, a website.visitor is not created yet, but the visitor can still start a livechat session. When navigating to a tracked page, a website.visitor is created but the lifechat session already started is not recovered and the discussion is lost at visitor's side. This commit links the already started livechat session to the newly created visitor to ensure that the conversation can still continue normally. 2. When a visitor logs in, his attributed visitor is linked to the partner. But there can be only one visitor per partner. If there was already a visitor linked to the partner, the later visitor's livechat session are updated with the partner and the visitor is then deleted. But the visitor's livechat sessions are not linked to the main partner visitor. So when looking at all the session the partner had, we can only see the main visitor's livechat session. This commit copy the livechat session of that later visitor to the main partner visitor to ensure keeping the complete livechat history for each partner. Task ID: 2460892 closes odoo/odoo#66179 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/website_livechat/models/website_visitor.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/addons/website_livechat/models/website_visitor.py b/addons/website_livechat/models/website_visitor.py
index 8a0017a7fed..46731aea585 100644
--- a/addons/website_livechat/models/website_visitor.py
+++ b/addons/website_livechat/models/website_visitor.py
@@ -6,6 +6,7 @@ import json
from odoo import models, api, fields, _
from odoo.exceptions import UserError
+from odoo.http import request
class WebsiteVisitor(models.Model):
@@ -92,6 +93,12 @@ class WebsiteVisitor(models.Model):
notifications.append([(self._cr.dbname, 'res.partner', operator.partner_id.id), mail_channel_info])
self.env['bus.bus'].sendmany(notifications)
+ def _link_to_visitor(self, target, keep_unique=True):
+ """ Copy sessions of the secondary visitors to the main partner visitor. """
+ if target.partner_id:
+ target.mail_channel_ids |= self.mail_channel_ids
+ super(WebsiteVisitor, self)._link_to_visitor(target, keep_unique=keep_unique)
+
def _link_to_partner(self, partner, update_values=None):
""" Adapt partner in members of related livechats """
if partner:
@@ -100,3 +107,14 @@ class WebsiteVisitor(models.Model):
(4, partner.id),
]
super(WebsiteVisitor, self)._link_to_partner(partner, update_values=update_values)
+
+ def _create_visitor(self):
+ visitor = super(WebsiteVisitor, self)._create_visitor()
+ mail_channel_uuid = json.loads(request.httprequest.cookies.get('im_livechat_session', '{}')).get('uuid')
+ if mail_channel_uuid:
+ mail_channel = request.env["mail.channel"].sudo().search([("uuid", "=", mail_channel_uuid)])
+ mail_channel.write({
+ 'livechat_visitor_id': visitor.id,
+ 'anonymous_name': visitor.display_name
+ })
+ return visitor