[FIX] base: fix the default properties value
Bug === If we re-write the same definition record, the default values were applied again (even if the definition record didn't change). This is because the compute on the properties is called even if the definition record didn't change. Task-2965523 X-original-commit: 70d80771f2430f83c91e7ef46eeebde8de70c3fe Part-of: odoo/odoo#101487
This commit is contained in:
@@ -128,7 +128,7 @@ class PropertiesCase(TransactionCase):
|
||||
|
||||
expected = self.discussion_2.attributes_definition
|
||||
for property_definition in expected:
|
||||
property_definition['value'] = None
|
||||
property_definition['value'] = False
|
||||
|
||||
self.assertEqual(self.message_3.read(['attributes'])[0]['attributes'], expected)
|
||||
self.assertEqual(self.message_3.attributes, expected)
|
||||
@@ -489,7 +489,7 @@ class PropertiesCase(TransactionCase):
|
||||
"type": "char",
|
||||
"string": "Color Code",
|
||||
"default": "blue",
|
||||
"value": None,
|
||||
"value": False,
|
||||
}, {
|
||||
"name": "moderator_partner_id",
|
||||
"type": "many2one",
|
||||
@@ -557,7 +557,7 @@ class PropertiesCase(TransactionCase):
|
||||
'type': 'many2one',
|
||||
'comodel': 'res.partner',
|
||||
'default': (partner.id, partner.display_name),
|
||||
'value': None,
|
||||
'value': False,
|
||||
}],
|
||||
)
|
||||
partner.unlink()
|
||||
@@ -567,8 +567,8 @@ class PropertiesCase(TransactionCase):
|
||||
'name': 'moderator_partner_id',
|
||||
'type': 'many2one',
|
||||
'comodel': 'res.partner',
|
||||
'default': None,
|
||||
'value': None,
|
||||
'default': False,
|
||||
'value': False,
|
||||
}],
|
||||
)
|
||||
|
||||
@@ -1054,7 +1054,7 @@ class PropertiesCase(TransactionCase):
|
||||
'string': 'Partner',
|
||||
'type': 'many2one',
|
||||
'comodel': 'test_new_api.partner',
|
||||
'value': None,
|
||||
'value': False,
|
||||
}],
|
||||
msg='Should take the new definition when changing the definition record',
|
||||
)
|
||||
@@ -1115,7 +1115,7 @@ class PropertiesCase(TransactionCase):
|
||||
'type': 'many2one',
|
||||
'string': 'Partner',
|
||||
'comodel': 'test_new_api.partner',
|
||||
'value': None,
|
||||
'value': False,
|
||||
}],
|
||||
)
|
||||
|
||||
|
||||
+7
-7
@@ -3347,7 +3347,7 @@ class Properties(Field):
|
||||
for record in records:
|
||||
record[self.name] = self._add_default_values(
|
||||
record.env,
|
||||
{self.name: False, self.definition_record: record[self.definition_record]},
|
||||
{self.name: record[self.name], self.definition_record: record[self.definition_record]},
|
||||
)
|
||||
|
||||
def _add_default_values(self, env, values):
|
||||
@@ -3390,9 +3390,8 @@ class Properties(Field):
|
||||
|
||||
for properties_value in properties_list_values:
|
||||
if properties_value.get('value') is None:
|
||||
default = properties_value.get('default')
|
||||
if default:
|
||||
properties_value['value'] = default
|
||||
default = properties_value.get('default') or False
|
||||
properties_value['value'] = default
|
||||
|
||||
return properties_list_values
|
||||
|
||||
@@ -3428,7 +3427,7 @@ class Properties(Field):
|
||||
# protect from access error message, show an empty name
|
||||
property_definition[value_key] = (property_value, None)
|
||||
except MissingError:
|
||||
property_definition[value_key] = None
|
||||
property_definition[value_key] = False
|
||||
|
||||
elif property_type == 'many2many' and property_value and is_list_of(property_value, int):
|
||||
property_definition[value_key] = []
|
||||
@@ -3509,7 +3508,8 @@ class Properties(Field):
|
||||
# E.G. convert zero to False
|
||||
property_value = bool(property_value)
|
||||
|
||||
elif property_type == 'char' and not isinstance(property_value, str):
|
||||
elif property_type == 'char' and not isinstance(property_value, str) \
|
||||
and property_value is not None:
|
||||
property_value = False
|
||||
|
||||
elif property_value and property_type == 'selection':
|
||||
@@ -3586,7 +3586,7 @@ class Properties(Field):
|
||||
|
||||
dict_value = {}
|
||||
for property_definition in values_list:
|
||||
property_value = property_definition.get('value')
|
||||
property_value = property_definition.get('value') or False
|
||||
property_type = property_definition.get('type')
|
||||
property_model = property_definition.get('comodel')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user