diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py index 98b6c0033f46bd15e32664ca9392ef50a7f187fc..fb1d3372fa1b314c8053f775a9fe862b45280239 100644 --- a/opentech/apply/funds/models.py +++ b/opentech/apply/funds/models.py @@ -223,6 +223,12 @@ class Round(SubmittableStreamForm): ], heading="Dates") ] + def save(self, *args, **kwargs): + if 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) + def get_submit_meta_data(self, **kwargs): return super().get_submit_meta_data( page=self.get_parent(), diff --git a/opentech/apply/funds/tests/test_models.py b/opentech/apply/funds/tests/test_models.py index 6d4094dac5b8f662de9296c0ebdb6062b680d415..dab37d083ea336957a4777e9a7b5c8023885aded 100644 --- a/opentech/apply/funds/tests/test_models.py +++ b/opentech/apply/funds/tests/test_models.py @@ -68,7 +68,7 @@ class TestFundModel(TestCase): self.assertEqual(self.fund.open_round, None) -class TestRoundModel(TestCase): +class TestRoundModelDates(TestCase): def setUp(self): self.fund = FundTypeFactory(parent=None) @@ -139,6 +139,18 @@ class TestRoundModel(TestCase): new_round.clean() +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.parent_page = self.fund + + def test_workflow_is_copied_to_new_rounds(self): + self.round.save() + self.assertEqual(self.round.workflow, self.fund.workflow) + + class TestFormSubmission(TestCase): def setUp(self): self.site = Site.objects.first()