[FIX] base: fix selection properties in list view

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 <ryv@odoo.com>
Signed-off-by: Stéphane Debauche (std) <std@odoo.com>
This commit is contained in:
std-odoo
2023-06-06 11:45:19 +02:00
parent 6741ebdd62
commit b90d471e6b
2 changed files with 25 additions and 0 deletions
@@ -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...).
+5
View File
@@ -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