From 0d3d3f20b11a27c1f6318df74b149dd3db9d76dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Sat, 1 Sep 2018 01:02:03 +0200 Subject: [PATCH] Improve ModelStorage.copy * Allow callable in copy default * Support dotted notation in copy default * Use setdefault in copy * Copy default when needed * Do not set default state in copy * Use callable and dotted notation in copy default issue5576 issue7648 review72291002 --- work.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/work.py b/work.py index ed1e249fa4..5d196c7be6 100644 --- a/work.py +++ b/work.py @@ -380,19 +380,10 @@ class Work(sequence_ordered(), tree(separator='\\'), ModelSQL, ModelView): def copy(cls, project_works, default=None): if default is None: default = {} - - timesheet_default = default.copy() - for key in list(timesheet_default.keys()): - if key in cls._fields: - del timesheet_default[key] - timesheet_default['children'] = None - new_project_works = [] - for project_work in project_works: - pwdefault = default.copy() - pwdefault['children'] = None - new_project_works.extend(super(Work, cls).copy([project_work], - default=pwdefault)) - return new_project_works + else: + default = default.copy() + default.setdefault('children', None) + return super().copy(project_works, default=default) @classmethod def delete(cls, project_works):