From cbb4bdc04f7cae0034e047bb666912486f1b6d8d Mon Sep 17 00:00:00 2001
From: Todd Dembrey <todd.dembrey@torchbox.com>
Date: Thu, 14 Jun 2018 14:35:13 +0100
Subject: [PATCH] Provide a method to reset the current stage

---
 opentech/apply/funds/models.py | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/opentech/apply/funds/models.py b/opentech/apply/funds/models.py
index 6c8b7772f..92775fc41 100644
--- a/opentech/apply/funds/models.py
+++ b/opentech/apply/funds/models.py
@@ -16,7 +16,7 @@ from django.urls import reverse
 from django.utils.text import mark_safe, slugify
 from django.utils.translation import ugettext_lazy as _
 
-from django_fsm import FSMField, transition
+from django_fsm import FSMField, transition, RETURN_VALUE
 from modelcluster.fields import ParentalKey, ParentalManyToManyField
 from wagtail.admin.edit_handlers import (
     FieldPanel,
@@ -553,6 +553,17 @@ class ApplicationSubmission(WorkflowHelpers, BaseStreamForm, AbstractFormSubmiss
 
     objects = ApplicationSubmissionQueryset.as_manager()
 
+    def not_progressed(self):
+        return not self.next and self.workflow != WORKFLOWS['single']
+
+    @transition(
+        status, source='*',
+        target=RETURN_VALUE(INITIAL_STATE, 'draft_proposal'),
+        conditions=[not_progressed]
+    )
+    def restart_stage(self):
+        return self.workflow.stages.index(self.stage)[INITIAL_STATE, 'draft_proposal']
+
     @property
     def stage(self):
         return self.phase.stage
-- 
GitLab