[FIX] tools: prevent crash of formatLang

From Odoo 9.0, en_US is not always activated in Odoo. As a fallback, if
the search for a language does not find company language nor English US,
we use the first available language (there is always at least one).

In order to reproduce this behavior, eg: you can set the language of
your company's partner to en_US, then load another language, then
disable en_US from your database. Try to open the "Accounting" dashboard
and you will get a traceback.
This commit is contained in:
Richard Mathot
2016-09-06 09:37:04 +02:00
parent e424a9a938
commit c208d0e0b2
+1 -1
View File
@@ -1184,7 +1184,7 @@ def formatLang(env, value, digits=None, grouping=True, monetary=False, dp=False,
lang = env.user.company_id.partner_id.lang or 'en_US'
lang_objs = env['res.lang'].search([('code', '=', lang)])
if not lang_objs:
lang_objs = env['res.lang'].search([('code', '=', 'en_US')])
lang_objs = env['res.lang'].search([], limit=1)
lang_obj = lang_objs[0]
res = lang_obj.format('%.' + str(digits) + 'f', value, grouping=grouping, monetary=monetary)