From a4f5beab63e9fc9fa65e17173a4aa93ba902bb87 Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Thu, 5 Feb 2026 08:11:38 +0100 Subject: [PATCH 1/2] Move save to log_status_update so e-mail get sent. --- hypha/apply/funds/models/submissions.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hypha/apply/funds/models/submissions.py b/hypha/apply/funds/models/submissions.py index 3541926343..7a73a424ab 100644 --- a/hypha/apply/funds/models/submissions.py +++ b/hypha/apply/funds/models/submissions.py @@ -375,11 +375,7 @@ def perform_transition(self, action, user, request=None, **kwargs): raise PermissionDenied(f'You do not have permission to "{action}"') # Execute the transition - result = transition_method(by=user, request=request, **kwargs) - if result: - self.status = action - self.save(update_fields=["status"]) - + transition_method(by=user, request=request, **kwargs) self.progress_stage_when_possible(user, request, **kwargs) attrs["perform_transition"] = perform_transition @@ -1038,6 +1034,9 @@ def get_no_screening_status(self): @status_field.on_success() def log_status_update(self, descriptor, source, target, **kwargs): instance = self + # Update status on instance. + instance.status = target + instance.save(update_fields=["status"]) # The status associated with the application at this time will be the old phase # so provide the new phase as an arg when transitioning From 90651a81da4a78375244effb4322c4554079a51e Mon Sep 17 00:00:00 2001 From: Fredrik Jonsson Date: Thu, 5 Feb 2026 09:30:50 +0100 Subject: [PATCH 2/2] Revert changes from #4621 since we now save the submission earlier. --- hypha/apply/activity/adapters/activity_feed.py | 8 +++----- hypha/apply/activity/adapters/base.py | 2 +- hypha/apply/activity/adapters/emails.py | 10 +++------- hypha/apply/activity/adapters/slack.py | 2 +- hypha/apply/funds/models/submissions.py | 8 +++----- 5 files changed, 11 insertions(+), 19 deletions(-) diff --git a/hypha/apply/activity/adapters/activity_feed.py b/hypha/apply/activity/adapters/activity_feed.py index 64c85aeded..570129dfa6 100644 --- a/hypha/apply/activity/adapters/activity_feed.py +++ b/hypha/apply/activity/adapters/activity_feed.py @@ -221,7 +221,7 @@ def handle_task_removal(self, source, task, **kwargs): ) ) - def handle_transition(self, new_phase, source, old_phase=None, **kwargs): + def handle_transition(self, old_phase, source, **kwargs): def wrap_in_color_class(text): color_class = PHASE_BG_COLORS.get(text, "") return f'{text}' @@ -229,8 +229,7 @@ def wrap_in_color_class(text): submission = source base_message = _("Progressed from {old_display} to {new_display}") - if old_phase is None: - old_phase = submission.phase + new_phase = submission.phase staff_message = base_message.format( old_display=wrap_in_color_class(old_phase.display_name), @@ -284,9 +283,8 @@ def handle_batch_transition(self, transitions, sources, **kwargs): kwargs.pop("source") for submission in submissions: old_phase = transitions[submission.id] - new_phase = submission.phase return self.handle_transition( - old_phase=old_phase, new_phase=new_phase, source=submission, **kwargs + old_phase=old_phase, source=submission, **kwargs ) def partners_updated(self, added, removed, **kwargs): diff --git a/hypha/apply/activity/adapters/base.py b/hypha/apply/activity/adapters/base.py index 2080f4ebfa..c88813ec5d 100644 --- a/hypha/apply/activity/adapters/base.py +++ b/hypha/apply/activity/adapters/base.py @@ -8,7 +8,7 @@ MESSAGES.BATCH_DETERMINATION_OUTCOME: "determinations", MESSAGES.UPDATE_LEAD: "old_lead", MESSAGES.NEW_REVIEW: "review", - MESSAGES.TRANSITION: "new_phase", + MESSAGES.TRANSITION: "old_phase", MESSAGES.BATCH_TRANSITION: "transitions", MESSAGES.APPLICANT_EDIT: "revision", MESSAGES.INVITE_COAPPLICANT: "co_applicant_invite", diff --git a/hypha/apply/activity/adapters/emails.py b/hypha/apply/activity/adapters/emails.py index e152606781..7ad318ae63 100644 --- a/hypha/apply/activity/adapters/emails.py +++ b/hypha/apply/activity/adapters/emails.py @@ -163,21 +163,18 @@ def extra_kwargs(self, message_type, source, sources, **kwargs): "subject": self.get_subject(message_type, source), } - def handle_transition(self, new_phase, source, old_phase=None, **kwargs): + def handle_transition(self, old_phase, source, **kwargs): from hypha.apply.funds.workflows import PHASES submission = source - if old_phase is None: - old_phase = submission.phase - # Retrieve status index to see if we are going forward or backward. old_index = list(dict(PHASES).keys()).index(old_phase.name) target_index = list(dict(PHASES).keys()).index(submission.status) is_forward = old_index < target_index kwargs["old_phase"] = old_phase.public_name - kwargs["new_phase"] = new_phase.public_name + kwargs["new_phase"] = submission.phase.public_name if is_forward: return self.render_message( @@ -210,9 +207,8 @@ def handle_batch_transition(self, transitions, sources, **kwargs): kwargs.pop("source") for submission in submissions: old_phase = transitions[submission.id] - new_phase = submission.phase return self.handle_transition( - old_phase=old_phase, new_phase=new_phase, source=submission, **kwargs + old_phase=old_phase, source=submission, **kwargs ) def handle_project_transition(self, source, **kwargs): diff --git a/hypha/apply/activity/adapters/slack.py b/hypha/apply/activity/adapters/slack.py index d23914b6e2..f4fec18519 100644 --- a/hypha/apply/activity/adapters/slack.py +++ b/hypha/apply/activity/adapters/slack.py @@ -49,7 +49,7 @@ class SlackAdapter(AdapterBase): "{user} has updated the partners on <{link}|{source.title_text_display}>" ), MESSAGES.TRANSITION: _( - "{user} has updated the status of <{link}|{source.title_text_display}>: {source.phase.display_name} → {new_phase.display_name}" + "{user} has updated the status of <{link}|{source.title_text_display}>: {old_phase.display_name} → {source.phase.display_name}" ), MESSAGES.BATCH_TRANSITION: "handle_batch_transition", MESSAGES.DETERMINATION_OUTCOME: "handle_determination", diff --git a/hypha/apply/funds/models/submissions.py b/hypha/apply/funds/models/submissions.py index 7a73a424ab..01112ec0f2 100644 --- a/hypha/apply/funds/models/submissions.py +++ b/hypha/apply/funds/models/submissions.py @@ -1034,14 +1034,12 @@ def get_no_screening_status(self): @status_field.on_success() def log_status_update(self, descriptor, source, target, **kwargs): instance = self + old_phase = instance.workflow[source] + # Update status on instance. instance.status = target instance.save(update_fields=["status"]) - # The status associated with the application at this time will be the old phase - # so provide the new phase as an arg when transitioning - new_phase = self.workflow[target] - by = kwargs["by"] request = kwargs["request"] notify = kwargs.get("notify", True) @@ -1065,7 +1063,7 @@ def log_status_update(self, descriptor, source, target, **kwargs): user=by, request=request, source=instance, - related=new_phase, + related=old_phase, ) if instance.status in review_statuses: