diff --git a/caluma/caluma_form/models.py b/caluma/caluma_form/models.py index 03cc7e5c5..fe695a924 100644 --- a/caluma/caluma_form/models.py +++ b/caluma/caluma_form/models.py @@ -396,10 +396,15 @@ def set_family(self, root_doc): def copy(self, family=None, user=None): """Create a copy including all its answers.""" + from caluma.caluma_form.utils import recalculate_answers_from_document + + # defer calculated questions, as many unecessary recomputations will happen otherwise + meta = dict(self.meta) + meta["_defer_calculation"] = True new_document = type(self).objects.create( form=self.form, - meta=dict(self.meta), + meta=meta, source=self, family=family, created_by_user=user.username if user else None, @@ -416,6 +421,10 @@ def copy(self, family=None, user=None): document_family=family, to_document=new_document, user=user ) + new_document.meta.pop("_defer_calculation", None) + new_document.save() + recalculate_answers_from_document(new_document) + return new_document @cached_property