Skip to content
Permalink
Browse files

[FIX] base: qweb t-call propagates t-lang

Before this commit, the t-lang on a t-call was not
propagated into the context's of the callee template

It resulted into mismatch translation and formatting in the final
rendered template
i.e. having a t-esc with a qweb widget float would take the wrong float format

After this commit, the t-lang parameter alters the context of the template
and t-esc with widgets are translated

OPW 1939989
  • Loading branch information...
kebeclibre committed Feb 20, 2019
1 parent 09bf391 commit 45e81488776463259d43ff8ab94f34fc1981118a
Showing with 92 additions and 2 deletions.
  1. +51 −2 odoo/addons/base/ir/ir_qweb/qweb.py
  2. +41 −0 odoo/addons/base/tests/test_qweb.py
@@ -1458,7 +1458,7 @@ def _compile_directive_call(self, el, options):
)

if call_options:
# update this dict with the content of `t-call-options`
# update this dict with the content of `t-call-options`
content.extend([
# options_.update(template options)
ast.Expr(ast.Call(
@@ -1469,7 +1469,56 @@ def _compile_directive_call(self, el, options):
),
args=[self._compile_expr(call_options)],
keywords=[], starargs=None, kwargs=None
))
)),

# if options.get('lang') != options_.get('lang'):
# self = self.with_context(lang=options.get('lang'))
ast.If(
test=ast.Compare(
left=ast.Call(
func=ast.Attribute(
value=ast.Name(id='options', ctx=ast.Load()),
attr='get',
ctx=ast.Load()
),
args=[ast.Str("lang")], keywords=[],
starargs=None, kwargs=None
),
ops=[ast.NotEq()],
comparators=[ast.Call(
func=ast.Attribute(
value=ast.Name(id=name_options, ctx=ast.Load()),
attr='get',
ctx=ast.Load()
),
args=[ast.Str("lang")], keywords=[],
starargs=None, kwargs=None
)]
),
body=[
ast.Assign(
targets=[ast.Name(id='self', ctx=ast.Store())],
value=ast.Call(
func=ast.Attribute(
value=ast.Name(id='self', ctx=ast.Load()),
attr='with_context',
ctx=ast.Load()
),
args=[],
keywords=[ast.keyword('lang', ast.Call(
func=ast.Attribute(
value=ast.Name(id=name_options, ctx=ast.Load()),
attr='get',
ctx=ast.Load()
),
args=[ast.Str("lang")], keywords=[],
starargs=None, kwargs=None
))],
starargs=None, kwargs=None
)
)],
orelse=[],
)
])

if nsmap:
@@ -489,6 +489,47 @@ def test_render_dynamic_xml_with_code_error(self):
with self.assertRaises(QWebException, msg=error_msg):
view1.render()

def test_render_t_call_propagates_t_lang(self):
current_lang = 'en_US'
other_lang = 'fr_FR'

self.env['res.lang'].load_lang(lang=other_lang)

self.env['res.lang'].search([('code', '=', other_lang)], limit=1).write({
'active': True,
'decimal_point': '*',
'thousands_sep': '/'
})

view1 = self.env['ir.ui.view'].create({
'name': "callee",
'type': 'qweb',
'arch': u"""
<t t-name="base.callee">
<t t-esc="9000000.00" t-options="{'widget': 'float', 'precision': 2}" />
</t>
"""
})
self.env['ir.model.data'].create({
'name': 'callee',
'model': 'ir.ui.view',
'module': 'base',
'res_id': view1.id,
})

view2 = self.env['ir.ui.view'].create({
'name': "calling",
'type': 'qweb',
'arch': u"""
<t t-name="base.calling">
<t t-call="base.callee" t-lang="'%s'" />
</t>
""" % other_lang
})

rendered = view2.with_context(lang=current_lang).render().strip()
self.assertEqual(rendered, b'9/000/000*00')


from copy import deepcopy
class FileSystemLoader(object):

0 comments on commit 45e8148

Please sign in to comment.
You can’t perform that action at this time.