[FIX] base: ir.qweb.field.contact handle null value
In case where display_name is null, the widget contact crash - AttributeError: 'bool' object has no attribute 'split' On odoo.com we have around 3K of partner that have name with null value. So calling so widget Contact on linked res.users will crash since the display name is False closes odoo/odoo#155735 Signed-off-by: Rémy Voet (ryv) <ryv@odoo.com>
This commit is contained in:
@@ -781,15 +781,16 @@ class Contact(models.AbstractModel):
|
||||
opsep = Markup('<br/>')
|
||||
|
||||
value = value.sudo().with_context(show_address=True)
|
||||
display_name = value.display_name or ''
|
||||
# Avoid having something like:
|
||||
# display_name = 'Foo\n \n' -> This is a res.partner with a name and no address
|
||||
# That would return markup('<br/>') as address. But there is no address set.
|
||||
if any(elem.strip() for elem in value.display_name.split("\n")[1:]):
|
||||
address = opsep.join(value.display_name.split("\n")[1:]).strip()
|
||||
if any(elem.strip() for elem in display_name.split("\n")[1:]):
|
||||
address = opsep.join(display_name.split("\n")[1:]).strip()
|
||||
else:
|
||||
address = ''
|
||||
val = {
|
||||
'name': value.display_name.split("\n")[0],
|
||||
'name': display_name.split("\n")[0],
|
||||
'address': address,
|
||||
'phone': value.phone,
|
||||
'mobile': value.mobile,
|
||||
|
||||
@@ -1644,6 +1644,21 @@ class TestQWebBasic(TransactionCase):
|
||||
markupsafe.Markup(f'<p>{p_instruction}</p>'),
|
||||
"Should have the processing instruction")
|
||||
|
||||
def test_render_widget_contact(self):
|
||||
u = self.env['res.users'].create({
|
||||
'name': 'Test',
|
||||
'login': 'test@example.com',
|
||||
})
|
||||
u.name = ""
|
||||
view1 = self.env['ir.ui.view'].create({
|
||||
'name': "dummy",
|
||||
'type': 'qweb',
|
||||
'arch': """
|
||||
<t t-name="base.dummy"><root><span t-esc="user" t-options='{"widget": "contact", "fields": ["name"]}' /></root></t>
|
||||
"""
|
||||
})
|
||||
self.env['ir.qweb']._render(view1.id, {'user': u}) # should not crash
|
||||
|
||||
def test_void_element(self):
|
||||
view = self.env['ir.ui.view'].create({
|
||||
'name': 'master',
|
||||
|
||||
Reference in New Issue
Block a user