[FIX] base: fix t-field with empty value/default value

Since odoo/odoo#97347 we support default values for `t-field`
directives.
However this causes some issues in the case where we have: no value, no
default value AND force_display is true.
This is because the indentation for one of the lines in the compiled
code was not correct. (full explanation here: https://github.com/odoo/odoo/pull/97347#issuecomment-1222430659)

closes odoo/odoo#98714

X-original-commit: 2b605d3ccd55dc4f5b1ad44439411542e5b04b31
Signed-off-by: Rémy Voet <ryv@odoo.com>
Signed-off-by: William Braeckman (wbr) <wbr@odoo.com>
This commit is contained in:
William Braeckman
2022-08-23 17:55:35 +02:00
parent 381c0f0228
commit bb4324a69e
+18
View File
@@ -143,6 +143,24 @@ class TestQWebTField(TransactionCase):
})
self.assertEqual(str(rendered.strip()), result.strip())
def test_no_value_no_default_value(self):
# no value, no default value with attributes on t-field
t = self.env['ir.ui.view'].create({
'name': 'test',
'type': 'qweb',
'arch_db': '''<t t-name="out-field-default">
<div t-field="record.name"/>
</t>''',
})
result = """
<div data-oe-xpath="/t[1]/div[1]" data-oe-model="res.partner" data-oe-field="name" data-oe-type="char" data-oe-expression="record.name"></div>
"""
# inherit_branding puts attribute on the field tag as well as force the display in case the field is empty
rendered = self.env['ir.qweb'].with_context(inherit_branding=True)._render(t.id, {
'record': self.env['res.partner'].new({}),
})
self.assertEqual(str(rendered.strip()), result.strip())
class TestQWebNS(TransactionCase):
def test_render_static_xml_with_namespace(self):