From ab7ab7ebbb094c3fcce416a6ee26da6451280084 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 20 Jun 2019 07:55:28 +0000 Subject: [PATCH] [FIX] web,http_routing: correctly invalidate cache translation cache_hashes was introduced at 8a28cc22fd242f to reduce the number of reload The cache is correctly reseted when the translations content changed but did not contain all the translation-related parameters that are, however, stored in the session_info This commit fixes two bugs: Language parameters invalidation: 1. Access the webclient in a specific language 2. Modify the language parameters (e.g. thousands separator) 3. Refresh the page --> webclient is still using old language parameters (from cache) No translation flag after installing a language: 1. Load a database in English in mono-language 2. Load a second language 3. Access a record with a translated field --> translation button not present on translated field (multi_lang is still false in cache value) To fix it, this commit adds all the information that are returns by the /web/webclient/translations call to make sure the hash represent the reality closes odoo/odoo#34266 Signed-off-by: Martin Trigaux (mat) --- addons/http_routing/models/ir_http.py | 9 +++++++-- addons/web/models/ir_http.py | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index b6d0361498a..643d378e9ce 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -246,12 +246,17 @@ class IrHttp(models.AbstractModel): modules = IrHttpModel.get_translation_frontend_modules() user_context = request.session.get_context() if request.session.uid else {} lang = user_context.get('lang') - translations, _ = request.env['ir.translation'].get_translations_for_webclient(modules, lang) + translations, lang_params = request.env['ir.translation'].get_translations_for_webclient(modules, lang) + translation_cache = { + 'lang_parameters': lang_params, + 'modules': translations, + 'multi_lang': len(request.env['res.lang'].sudo().get_installed()) > 1, + } session_info.update({ 'translationURL': '/website/translations/', 'cache_hashes': { - 'translations': hashlib.sha1(json.dumps(translations, sort_keys=True).encode()).hexdigest(), + 'translations': hashlib.sha1(json.dumps(translation_cache, sort_keys=True).encode()).hexdigest(), }, }) return session_info diff --git a/addons/web/models/ir_http.py b/addons/web/models/ir_http.py index f2bfc70f9b4..df316c582fd 100644 --- a/addons/web/models/ir_http.py +++ b/addons/web/models/ir_http.py @@ -32,10 +32,15 @@ class Http(models.AbstractModel): _, qweb_checksum = concat_xml(files) lang = user_context.get("lang") - translations_per_module, _ = request.env['ir.translation'].get_translations_for_webclient(mods, lang) + translations_per_module, lang_params = request.env['ir.translation'].get_translations_for_webclient(mods, lang) + translation_cache = { + 'lang_parameters': lang_params, + 'modules': translations_per_module, + 'multi_lang': len(request.env['res.lang'].sudo().get_installed()) > 1, + } menu_json_utf8 = json.dumps(request.env['ir.ui.menu'].load_menus(request.session.debug), default=ustr, sort_keys=True).encode() - translations_json_utf8 = json.dumps(translations_per_module, sort_keys=True).encode() + translations_json_utf8 = json.dumps(translation_cache, sort_keys=True).encode() return { "uid": request.session.uid,