Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] base: duration widget for unsupported babel format #155978

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 20 additions & 7 deletions odoo/addons/base/models/ir_qweb_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,26 @@ def value_to_html(self, value, options):
v, r = divmod(r, secs_per_unit)
if not v:
continue
section = babel.dates.format_timedelta(
v*secs_per_unit,
granularity=round_to,
add_direction=options.get('add_direction'),
format=options.get('format', 'long'),
threshold=1,
locale=locale)
try:
section = babel.dates.format_timedelta(
v*secs_per_unit,
granularity=round_to,
add_direction=options.get('add_direction'),
format=options.get('format', 'long'),
threshold=1,
locale=locale)
except KeyError:
# in case of wrong implementation of babel, try to fallback on en_US locale.
# https://github.com/python-babel/babel/pull/827/files
# Some bugs already fixed in 2.10 but ubuntu22 is 2.8
localeUS = babel_locale_parse('en_US')
section = babel.dates.format_timedelta(
v*secs_per_unit,
granularity=round_to,
add_direction=options.get('add_direction'),
format=options.get('format', 'long'),
threshold=1,
locale=localeUS)
if section:
sections.append(section)

Expand Down
11 changes: 11 additions & 0 deletions odoo/addons/base/tests/test_qweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,6 +1659,17 @@ def test_render_widget_contact(self):
})
self.env['ir.qweb']._render(view1.id, {'user': u}) # should not crash

def test_render_widget_duration_fallback(self):
self.env['res.lang'].with_context(active_test=False).search([('code', '=', 'pt_BR')]).active = True
view1 = self.env['ir.ui.view'].create({
'name': "dummy",
'type': 'qweb',
'arch': """
<t t-name="base.dummy"><root><span t-esc="3600" t-options='{"widget": "duration", "format": "short"}' /></root></t>
"""
})
self.env['ir.qweb'].with_context(lang='pt_BR')._render(view1.id, {}) # should not crash

def test_void_element(self):
view = self.env['ir.ui.view'].create({
'name': 'master',
Expand Down