diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 64d31590a59b7b373d1524c5bc0ffb5c74b4ed58..dea64c76cb9d2df8ff4a4ce09a385e5168081c03 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -239,13 +239,15 @@ class Round(SubmittableStreamForm): ], heading="Dates"), ] - def create(self, *args, **kwargs): - if hasattr(self, 'parent_page'): + def save(self, *args, **kwargs): + is_new = not self.id + if is_new and hasattr(self, 'parent_page'): # We attached the parent page as part of the before_create_hook self.workflow = self.parent_page.workflow super().save(*args, **kwargs) - if hasattr(self, 'parent_page'): + + if is_new and hasattr(self, 'parent_page'): for form in self.parent_page.forms.all(): # Create a copy of the existing form object new_form = form.form diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py index 946743da4b818691d262563480c20cc5e8d20c94..54a68669a5dc2bae15f0fc193f5834b2517619e4 100644 --- a/opentech/apply/funds/tests/test_models.py +++ b/opentech/apply/funds/tests/test_models.py @@ -144,10 +144,12 @@ class TestRoundModelDates(TestCase): class TestRoundModelWorkflowAndForms(TestCase): def setUp(self): self.fund = FundTypeFactory(parent=None) - # we only add parent_page on create, so if the object exists already this should not affect testing - self.round = RoundFactory() + + self.round = RoundFactory.build() self.round.parent_page = self.fund + self.fund.add_child(instance=self.round) + def test_workflow_is_copied_to_new_rounds(self): self.round.save() self.assertEqual(self.round.workflow, self.fund.workflow)