[FIX] im_livechat, website_livechat: fix use visitor name in livechat session
im_livechat main controller was referring to website.visitor but this module is not depending on website. The usage of website visitor's name should have been done in website_livechat module. This commit fix this issue. Task ID: 2116715 PR #40732 closes odoo/odoo#40884 X-original-commit: defb98c1083e55ff02f290c3c6257a4ca8dc7d1f Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user