From 4347491670cb0e1bef64084badeccd5b09a95377 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Tue, 21 Dec 2021 15:43:18 +0000 Subject: [PATCH] [FIX] core: unexpected display_name "False" If a form view contains the field 'display_name', when creating a new record, the initial value of 'display_name' is the string "False", and that weird value also appears in the breadcrumb instead of "New". In order to avoid this unexpected behavior, the conversion of a value to a display name should be False, like any other field would. closes odoo/odoo#81788 Signed-off-by: Raphael Collet --- odoo/addons/test_new_api/tests/test_onchange.py | 16 ++++++++++++++++ odoo/fields.py | 6 +++--- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/odoo/addons/test_new_api/tests/test_onchange.py b/odoo/addons/test_new_api/tests/test_onchange.py index 0d5b94495b0..c0e115bc704 100644 --- a/odoo/addons/test_new_api/tests/test_onchange.py +++ b/odoo/addons/test_new_api/tests/test_onchange.py @@ -585,6 +585,22 @@ class TestOnChange(SavepointCaseWithUserDemo): self.assertEqual(payment.tag_repeat, 3) self.assertEqual(payment.tag_string, 'BarBarBar') + def test_display_name(self): + self.env['ir.ui.view'].create({ + 'name': 'test_new_api.multi.tag form view', + 'model': 'test_new_api.multi.tag', + 'arch': """ +
+ + + + """, + }) + + form = common.Form(self.env['test_new_api.multi.tag']) + self.assertEqual(form.name, False) + self.assertEqual(form.display_name, False) + class TestComputeOnchange(common.TransactionCase): diff --git a/odoo/fields.py b/odoo/fields.py index 07d1336a83f..3330a088449 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -921,7 +921,7 @@ class Field(MetaField('DummyField', (object,), {})): def convert_to_display_name(self, value, record): """ Convert ``value`` from the record format to a suitable display name. """ - return ustr(value) + return ustr(value) if value else False ############################################################################ # @@ -2639,7 +2639,7 @@ class Reference(Selection): return value.display_name if value else '' def convert_to_display_name(self, value, record): - return ustr(value and value.display_name) + return value.display_name if value else False class _Relational(Field): @@ -2882,7 +2882,7 @@ class Many2one(_Relational): return value.display_name if value else '' def convert_to_display_name(self, value, record): - return ustr(value.display_name) + return value.display_name def convert_to_onchange(self, value, record, names): if not value.id: