From 872debd91ba937081aff040864798acad9ef2c6e Mon Sep 17 00:00:00 2001
From: Vaibhav Mule <vaibhavmule135@gmail.com>
Date: Mon, 18 May 2020 18:23:34 +0530
Subject: [PATCH] fix notifications

---
 hypha/apply/funds/models/submissions.py | 22 +++++++++++++++-------
 hypha/apply/funds/models/utils.py       | 15 ++++++++-------
 2 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/hypha/apply/funds/models/submissions.py b/hypha/apply/funds/models/submissions.py
index ad8876357..3fdaab7ef 100644
--- a/hypha/apply/funds/models/submissions.py
+++ b/hypha/apply/funds/models/submissions.py
@@ -790,13 +790,21 @@ def log_status_update(sender, **kwargs):
     notify = kwargs['method_kwargs'].get('notify', True)
 
     if request and notify:
-        messenger(
-            MESSAGES.TRANSITION,
-            user=by,
-            request=request,
-            source=instance,
-            related=old_phase,
-        )
+        if kwargs['source'] == DRAFT:
+            messenger(
+                MESSAGES.NEW_SUBMISSION,
+                request=request,
+                user=by,
+                source=instance,
+            )
+        else:
+            messenger(
+                MESSAGES.TRANSITION,
+                user=by,
+                request=request,
+                source=instance,
+                related=old_phase,
+            )
 
         if instance.status in review_statuses:
             messenger(
diff --git a/hypha/apply/funds/models/utils.py b/hypha/apply/funds/models/utils.py
index 7d7f7e23b..b3f7500d4 100644
--- a/hypha/apply/funds/models/utils.py
+++ b/hypha/apply/funds/models/utils.py
@@ -18,7 +18,7 @@ from hypha.apply.users.groups import (
     STAFF_GROUP_NAME,
 )
 
-from ..workflow import WORKFLOWS
+from ..workflow import DRAFT, WORKFLOWS
 
 REVIEW_GROUPS = [
     STAFF_GROUP_NAME,
@@ -103,12 +103,13 @@ class WorkflowStreamForm(WorkflowHelpers, AbstractStreamForm):  # type: ignore
     def render_landing_page(self, request, form_submission=None, *args, **kwargs):
         # We only reach this page after creation of a new submission
         # Hook in to notify about new applications
-        messenger(
-            MESSAGES.NEW_SUBMISSION,
-            request=request,
-            user=form_submission.user,
-            source=form_submission,
-        )
+        if not form_submission.status == DRAFT:
+            messenger(
+                MESSAGES.NEW_SUBMISSION,
+                request=request,
+                user=form_submission.user,
+                source=form_submission,
+            )
         return super().render_landing_page(request, form_submission=None, *args, **kwargs)
 
     content_panels = AbstractStreamForm.content_panels + [
-- 
GitLab