diff options
| author | David Beguin <dbe@odoo.com> | 2019-08-19 11:31:24 +0000 |
|---|---|---|
| committer | David Beguin <dbe@odoo.com> | 2019-08-20 08:02:46 +0000 |
| commit | c5500e685aeeb2a0b6dbedc2edc7be5647bf05d7 (patch) | |
| tree | 8e5c0b0eeb7462b16b0d70d07414318cedccbb9c /odoo/tools/misc.py | |
| parent | b4ef0299db0e1ba5073cebd99abf6720c142671d (diff) | |
[FIX] tools : use babel to format timedelta
Babel is already taking the language into account while
formating a time delta into a readable string like '2 minutes ago'.
_format_time_ago was put in translate.py file to be able to use
the _ translate class. But it can be placed in misc like other
format function already using babel.
This fix the PR #34624
and is linked to Task ID : 2028059
Task ID: 2055847
Closes PR #35806
Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'odoo/tools/misc.py')
| -rw-r--r-- | odoo/tools/misc.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index 3139cc1b526..7e069d22a77 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -1285,6 +1285,15 @@ def format_time(env, value, tz=False, time_format='medium', lang_code=False): return babel.dates.format_time(value, format=time_format, locale=locale) + +def _format_time_ago(env, time_delta, lang_code=False): + if not lang_code: + 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]) + locale = babel.Locale.parse(lang_code) + return babel.dates.format_timedelta(-time_delta, add_direction=True, locale=locale) + + def format_amount(env, amount, currency, lang_code=False): fmt = "%.{0}f".format(currency.decimal_places) lang = env['res.lang']._lang_get(lang_code or env.context.get('lang') or 'en_US') |
