From ea6aad812eef7d7d19db0709cd2b86c41750ee50 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 28 Feb 2024 12:16:29 +0100 Subject: [PATCH] [FIX] base: ir.qweb.field.contact handle null value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- odoo/addons/base/models/ir_qweb_fields.py | 7 ++++--- odoo/addons/base/tests/test_qweb.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/odoo/addons/base/models/ir_qweb_fields.py b/odoo/addons/base/models/ir_qweb_fields.py index 431a95d607a..3efe3dc30bc 100644 --- a/odoo/addons/base/models/ir_qweb_fields.py +++ b/odoo/addons/base/models/ir_qweb_fields.py @@ -781,15 +781,16 @@ class Contact(models.AbstractModel): opsep = Markup('
') 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('
') 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, diff --git a/odoo/addons/base/tests/test_qweb.py b/odoo/addons/base/tests/test_qweb.py index a57193dfe6c..07fa58091ea 100644 --- a/odoo/addons/base/tests/test_qweb.py +++ b/odoo/addons/base/tests/test_qweb.py @@ -1644,6 +1644,21 @@ class TestQWebBasic(TransactionCase): markupsafe.Markup(f'

{p_instruction}

'), "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': """ + + """ + }) + 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',