From c5e8969f0f5e1446a98e73f86cd1df787b2787d2 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 --- timesheet.py | 3 ++- work.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/timesheet.py b/timesheet.py index a153a7df36..2e99544a8b 100644 --- a/timesheet.py +++ b/timesheet.py @@ -24,7 +24,8 @@ class TimesheetLine(metaclass=PoolMeta): def copy(cls, records, default=None): if default is None: default = {} - default = default.copy() + else: + default = default.copy() default.setdefault('invoice_line', None) return super(TimesheetLine, cls).copy(records, default=default) diff --git a/work.py b/work.py index b6de430a32..aacfad497a 100644 --- a/work.py +++ b/work.py @@ -93,7 +93,8 @@ class Work(metaclass=PoolMeta): def copy(cls, records, default=None): if default is None: default = {} - default = default.copy() + else: + default = default.copy() default.setdefault('invoice_line', None) return super(Work, cls).copy(records, default=default)