[FIX] tools: always retrieve a langage on formatLang
- Since commit https://github.com/odoo/odoo/commit/f5cd483216af01001f44a41f7d48f042b9f56ff9 the method `_lang_get` doesn't fallback on a language if the asked language isn't found. This causes issues with `formatLang` that uses the language on the context, which is the language set on the client browser (in most cases). Meaning, if 'en_US' is the only installed language and a customer has set his browser to `fr_FR`, when calling `formatLang` this will crash since no language has been found and `format` on `res.lang` requires a singleton. closes odoo/odoo#35633 Signed-off-by: Toufik Benjaa (tbe) <tbe@odoo.com>
This commit is contained in:
+3
-2
@@ -1150,8 +1150,9 @@ def formatLang(env, value, digits=None, grouping=True, monetary=False, dp=False,
|
||||
if isinstance(value, str) and not value:
|
||||
return ''
|
||||
|
||||
lang = env.context.get('lang') or env.user.company_id.partner_id.lang or 'en_US'
|
||||
lang_obj = env['res.lang']._lang_get(lang)
|
||||
langs = [code for code, _ in env['res.lang'].get_installed()]
|
||||
lang_code = env.context['lang'] if env.context.get('lang') in langs else (env.user.company_id.partner_id.lang or langs[0])
|
||||
lang_obj = env['res.lang']._lang_get(lang_code)
|
||||
|
||||
res = lang_obj.format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user