diff --git a/addons/im_livechat/controllers/main.py b/addons/im_livechat/controllers/main.py index 22969a38c38..a4b5c7f8f9d 100644 --- a/addons/im_livechat/controllers/main.py +++ b/addons/im_livechat/controllers/main.py @@ -83,28 +83,24 @@ class LivechatController(http.Controller): def get_session(self, channel_id, anonymous_name, previous_operator_id=None, **kwargs): user_id = None country_id = None - visitor_name = anonymous_name # if the user is identifiy (eg: portal user on the frontend), don't use the anonymous name. The user will be added to session. if request.session.uid: user_id = request.env.user.id country_id = request.env.user.country_id.id else: - visitor_sudo = request.env['website.visitor']._get_visitor_from_request() - if visitor_sudo: - visitor_name = visitor_sudo.display_name # if geoip, add the country name to the anonymous name if request.session.geoip: # get the country of the anonymous person, if any country_code = request.session.geoip.get('country_code', "") country = request.env['res.country'].sudo().search([('code', '=', country_code)], limit=1) if country_code else None if country: - visitor_name = "%s (%s)" % (visitor_name, country.name) + anonymous_name = "%s (%s)" % (anonymous_name, country.name) country_id = country.id if previous_operator_id: previous_operator_id = int(previous_operator_id) - return request.env["im_livechat.channel"].with_context(lang=False).sudo().browse(channel_id)._open_livechat_mail_channel(visitor_name, previous_operator_id, user_id, country_id) + return request.env["im_livechat.channel"].with_context(lang=False).sudo().browse(channel_id)._open_livechat_mail_channel(anonymous_name, previous_operator_id, user_id, country_id) @http.route('/im_livechat/feedback', type='json', auth='public', cors="*") def feedback(self, uuid, rate, reason=None, **kwargs): diff --git a/addons/website_livechat/controllers/main.py b/addons/website_livechat/controllers/main.py index 57b5437e59a..4ab5e56fb61 100644 --- a/addons/website_livechat/controllers/main.py +++ b/addons/website_livechat/controllers/main.py @@ -3,9 +3,10 @@ from odoo import http, _ from odoo.http import request +from odoo.addons.im_livechat.controllers.main import LivechatController -class WebsiteLivechat(http.Controller): +class WebsiteLivechat(LivechatController): @http.route('/livechat', type='http', auth="public", website=True, sitemap=True) def channel_list(self, **kw): @@ -56,6 +57,14 @@ class WebsiteLivechat(http.Controller): } return request.render("website_livechat.channel_page", values) + @http.route('/im_livechat/get_session', type="json", auth='public', cors="*") + def get_session(self, channel_id, anonymous_name, previous_operator_id=None, **kwargs): + """ Override to use visitor name instead of 'Visitor' whenever a visitor start a livechat session. """ + visitor_sudo = request.env['website.visitor']._get_visitor_from_request() + if visitor_sudo: + anonymous_name = visitor_sudo.display_name + return super(WebsiteLivechat, self).get_session(channel_id, anonymous_name, previous_operator_id=previous_operator_id, **kwargs) + @http.route('/im_livechat/visitor_leave_session', type='json', auth="public") def visitor_leave_session(self, uuid): """ Called when the livechat visitor leaves the conversation.