From 10af0ea078f40faa1b43959d241ee89f49fee9b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sun, 18 Oct 2015 16:50:41 +0200 Subject: [PATCH] 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 --- trytond/model/modelstorage.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/trytond/model/modelstorage.py b/trytond/model/modelstorage.py index 68eb97caea..3bf82697b7 100644 --- a/trytond/model/modelstorage.py +++ b/trytond/model/modelstorage.py @@ -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)