Use empty value Function xxx2Many fields without initial value
Since d142b33fa3ab the on_change_with relies on _changed_value. But for Function xxx2Many fields if their value is not in the initial value, we should not retrieve it from the database because the result will be the same as the one set by on_change_with. Closes #12836
This commit is contained in:
1 parent
8197d55ed1
commit
0d437d341c
3 files changed
+24
No files matched your search
@@ -863,6 +863,8 @@ class ModelView(Model):
|
||||
targets = value
|
||||
if fname in init_values:
|
||||
init_targets = init_values._get(fname)
|
||||
elif isinstance(field, fields.Function):
|
||||
init_targets = []
|
||||
else:
|
||||
init_targets = getattr(init_record, fname, [])
|
||||
value = collections.defaultdict(list)
|
||||
|
||||
@@ -25,6 +25,12 @@ class ModelViewChangedValues(ModelView):
|
||||
], "MultiSelection")
|
||||
dictionary = fields.Dict(
|
||||
'test.modelview.changed_values.dictionary', "Dictionary")
|
||||
m2m_function = fields.Function(fields.Many2Many(
|
||||
'test.modelview.changed_values.target', None, None, "Targets"),
|
||||
'on_change_with_m2m_function')
|
||||
|
||||
def on_change_with_m2m_function(self, name=None):
|
||||
return
|
||||
|
||||
|
||||
class ModelViewChangedValuesDictSchema(DictSchemaMixin, ModelSQL):
|
||||
|
||||
@@ -109,6 +109,22 @@ class ModelView(unittest.TestCase):
|
||||
},
|
||||
})
|
||||
|
||||
@with_transaction()
|
||||
def test_changed_values_2many_function(self):
|
||||
"Test changed values for xxx2many function field"
|
||||
pool = Pool()
|
||||
Model = pool.get('test.modelview.changed_values')
|
||||
|
||||
with patch.object(
|
||||
Model, 'on_change_with_m2m_function') as on_change_with:
|
||||
on_change_with.return_value = [42]
|
||||
record = Model()
|
||||
record.m2m_function = record.on_change_with_m2m_function()
|
||||
|
||||
self.assertEqual(record._changed_values, {
|
||||
'm2m_function': {'add': [(0, {'id': 42})]},
|
||||
})
|
||||
|
||||
@with_transaction()
|
||||
def test_changed_values_stored(self):
|
||||
"Test stored changed values"
|
||||
|
||||
Reference in new issue
Block a user