From 5761b9a388edf0cd5d92ab280f4b78c6e84867aa Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Tue, 21 Mar 2017 16:22:58 +0100 Subject: [PATCH] [FIX] http: setup_lang in Safari When not logged in the webstie on Safari and clicking on "Have a Question? Chat with us", it creates a mail.channel from get_mail_channel and it also creates a translation. But with Safari, the accept_languages is set with the value 'fr-fr', and this value was set in the context as the lang='fr_fr'. So when the translation was created, a bad insert query was raised in sql because the lang didn't exist in the res.lang table. When a translation is created, the function _get_languages checked that the language is in the table. So it was impossible to use the chatter when the user is not logged. NB: interseting functions to see: -setup_lang in odoo/http.py -_dispatch in addons/website/models/ir_http.py -get_mail_channel in addons/im_livechat/models/im_livechat_channel.py opw:716519 --- openerp/http.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/openerp/http.py b/openerp/http.py index 4900e140ce0..c0ca2489afc 100644 --- a/openerp/http.py +++ b/openerp/http.py @@ -1357,9 +1357,16 @@ class Root(object): httprequest.session.db = db_monodb(httprequest) def setup_lang(self, httprequest): - if not "lang" in httprequest.session.context: - lang = httprequest.accept_languages.best or "en_US" - lang = babel.core.LOCALE_ALIASES.get(lang, lang).replace('-', '_') + if "lang" not in httprequest.session.context: + alang = httprequest.accept_languages.best or "en-US" + try: + code, territory, _, _ = babel.core.parse_locale(alang, sep='-') + if territory: + lang = '%s_%s' % (code, territory) + else: + lang = babel.code.LOCALE_ALIASES[code] + except (ValueError, KeyError): + lang = 'en_US' httprequest.session.context["lang"] = lang def get_request(self, httprequest):