From 4a37beeff641f6cf9206be80c0aabd7e7b9f6152 Mon Sep 17 00:00:00 2001 From: David Beguin Date: Tue, 24 Sep 2019 12:39:49 +0000 Subject: [PATCH] [FIX] website_livechat : fix history in discuss visitor banner Adding a string element to a list with += is not adding the element to the list but is instead adding every single character of the string as an element to the list. Building a string using a join method was resulting to an recent history displayed like H > O > M > E > ( > 8 > : > 4 > 2 > ) --> Should be : HOME (8:42) > Contact Us (8:45) Apart from that, since the tracking is now ordered by visit_datetime DESC, to have a chronological order, we need to reverse the list of last visited pages to have something like : Home (12:43) > About us (12:45) > Contact Us (12:52) instead of : Contact Us (12:52) > About us (12:45) > Home (12:43) Task ID: 2076190 PR #37340 --- addons/website_livechat/models/mail_channel.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/addons/website_livechat/models/mail_channel.py b/addons/website_livechat/models/mail_channel.py index 2eb94f89f8d..4152de2cfd5 100644 --- a/addons/website_livechat/models/mail_channel.py +++ b/addons/website_livechat/models/mail_channel.py @@ -50,13 +50,8 @@ class MailChannel(models.Model): :param visitor: website.visitor of the channel :return: arrow separated string containing navigation history information """ - history = [] - for page in visitor.website_track_ids: - if page.page_id: - history += page.page_id.name + ' (' + page.visit_datetime.strftime('%H:%M') + ')' - if len(history) == 3: - break - return ' → '.join(history) + recent_history = self.env['website.track'].search([('page_id', '!=', False), ('visitor_id', '=', visitor.id)], limit=3) + return ' → '.join(visit.page_id.name + ' (' + visit.visit_datetime.strftime('%H:%M') + ')' for visit in reversed(recent_history)) def close_livechat_request_session(self, type='leave', **kwargs): """ Set deactivate the livechat channel and notify (the operator) the reason of closing the session."""