Skip to content
Snippets Groups Projects
Commit e974e1ae authored by Toufik Ben Jaa's avatar Toufik Ben Jaa
Browse files

[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: default avatarToufik Benjaa (tbe) <tbe@odoo.com>
parent 60c6eedc
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment