Reset MPTT fields when copying records

The left/right fields must be reset to their default values to allow to compute
the correct new values. As it is common to forget this requirement when
implementing, it is safer to enforce this behaviour directly in the
ModelStorage.copy method.

issue5049
review16741002
This commit is contained in:
Cédric Krier committed 2015-10-18 16:50:41 +02:00
1 parent 0e467f1b5d
commit 10af0ea078
1 file changed
+10 -1
+10 -1
View File
@@ -297,9 +297,18 @@ class ModelStorage(Model):
del data['id']
return data
# Reset MPTT field to the default value
mptt = set()
for field in cls._fields.itervalues():
if (isinstance(field, fields.Many2One)
and field.model_name == cls.__name__
and field.left and field.right):
mptt.add(field.left)
mptt.add(field.right)
fields_names = [n for n, f in cls._fields.iteritems()
if (not isinstance(f, fields.Function)
or isinstance(f, fields.Property))]
or isinstance(f, fields.Property))
and n not in mptt]
ids = map(int, records)
datas = cls.read(ids, fields_names=fields_names)
datas = dict((d['id'], d) for d in datas)