From b90d471e6b4e3b456ceb9e9d7a04fa817b02c9cc Mon Sep 17 00:00:00 2001 From: std-odoo Date: Tue, 30 May 2023 12:58:54 +0000 Subject: [PATCH] [FIX] base: fix selection properties in list view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug === The web client expects the selection key to be at least an empty array. (never false), like for a normal selection field, and so if the selection has been created without an option, it crashes in the list view. For consistency, we also set an array when there are no tags. Task-3340671 closes odoo/odoo#123844 X-original-commit: 2e38397c2cfe0e4ed501d4ce7b98f0c47fe6c344 Signed-off-by: Rémy Voet Signed-off-by: Stéphane Debauche (std) --- .../test_new_api/tests/test_properties.py | 20 +++++++++++++++++++ odoo/fields.py | 5 +++++ 2 files changed, 25 insertions(+) diff --git a/odoo/addons/test_new_api/tests/test_properties.py b/odoo/addons/test_new_api/tests/test_properties.py index 8b423471a44..242891b6b9d 100644 --- a/odoo/addons/test_new_api/tests/test_properties.py +++ b/odoo/addons/test_new_api/tests/test_properties.py @@ -931,6 +931,16 @@ class PropertiesCase(TestPropertiesMixin): } ] + self.message_3.attributes = [{ + 'type': 'selection', + 'name': 'new_selection', + 'string': 'My Selection', + 'definition_changed': True, + }] + values = self.message_3.read(['attributes'])[0]['attributes'][0] + self.assertEqual(values.get('name'), 'new_selection') + self.assertEqual(values.get('selection'), [], 'Selection key should be at least an empty array (never False)') + def test_properties_field_tags(self): """Test the behavior of the tag property. @@ -1007,6 +1017,16 @@ class PropertiesCase(TestPropertiesMixin): }, ] + self.message_3.attributes = [{ + 'type': 'tags', + 'name': 'new_tags', + 'string': 'My tags', + 'definition_changed': True, + }] + values = self.message_3.read(['attributes'])[0]['attributes'][0] + self.assertEqual(values.get('name'), 'new_tags') + self.assertEqual(values.get('tags'), [], 'Tags key should be at least an empty array (never False)') + @mute_logger('odoo.models.unlink', 'odoo.fields') def test_properties_field_many2many_basic(self): """Test the basic operation on a many2many properties (read, write...). diff --git a/odoo/fields.py b/odoo/fields.py index 100ed964bc6..3dc31579844 100644 --- a/odoo/fields.py +++ b/odoo/fields.py @@ -3830,6 +3830,11 @@ class PropertiesDefinition(Field): if not property_model and 'domain' in property_definition: del property_definition['domain'] + if property_definition.get('type') in ('selection', 'tags'): + # always set at least an empty array if there's no option + key = property_definition['type'] + property_definition[key] = property_definition.get(key) or [] + property_domain = property_definition.get('domain') if property_domain: # some fields in the domain might have been removed