Skip to content

Commit 27ffe10

Browse files
chore: decouple subsidy actions and user message dependencies
1 parent d0cfb0c commit 27ffe10

File tree

2 files changed

+56
-16
lines changed

2 files changed

+56
-16
lines changed

enterprise_access/apps/subsidy_request/constants.py

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ class SubsidyRequestStates:
3434

3535
CHOICES = COMMON_STATES + LC_REQUEST_STATES
3636

37-
37+
# DEPRECATED: This class was used to add 'reminded' to the list of possible
38+
# actions. Its functionality has been consolidated into the self-contained
39+
# `LearnerCreditRequestActionTypes` class.
3840
class LearnerCreditAdditionalActionStates:
3941
""" Additional states specifically for LearnerCreditRequestActions. """
4042

@@ -43,8 +45,8 @@ class LearnerCreditAdditionalActionStates:
4345
(REMINDED, "Reminded"),
4446
)
4547

46-
47-
# Combined choices for LearnerCreditRequestAction model
48+
# DEPRECATED: This variable combined states from multiple classes in a way that
49+
# was confusing and brittle. Use `LearnerCreditRequestActionTypes.CHOICES` instead.
4850
LearnerCreditRequestActionChoices = SubsidyRequestStates.CHOICES + LearnerCreditAdditionalActionStates.CHOICES
4951

5052

@@ -84,21 +86,59 @@ class SubsidyTypeChoices:
8486

8587
SUBSIDY_REQUEST_BULK_OPERATION_BATCH_SIZE = 100
8688

89+
class LearnerCreditRequestActionTypes:
90+
"""
91+
Defines the set of possible values for the `recent_action` field on the
92+
`LearnerCreditRequestActions` model. This represents the specific event
93+
or operation that occurred (e.g., an approval, a reminder).
94+
"""
95+
REQUESTED = 'requested'
96+
APPROVED = 'approved'
97+
DECLINED = 'declined'
98+
ERROR = 'error'
99+
ACCEPTED = 'accepted'
100+
CANCELLED = 'cancelled'
101+
EXPIRED = 'expired'
102+
REVERSED = 'reversed'
103+
REMINDED = 'reminded'
104+
105+
CHOICES = (
106+
(REQUESTED, "Requested"),
107+
(APPROVED, "Approved"),
108+
(DECLINED, "Declined"),
109+
(ERROR, "Error"),
110+
(ACCEPTED, "Accepted"),
111+
(CANCELLED, "Cancelled"),
112+
(EXPIRED, "Expired"),
113+
(REVERSED, "Reversed"),
114+
(REMINDED, "Reminded"),
115+
)
116+
87117

88118
class LearnerCreditRequestUserMessages:
89119
"""
90-
User-facing messages for LearnerCreditRequestActions status field.
91-
Reusing the state keys from SubsidyRequestStates but with different display messages.
120+
Defines the set of possible values for the `status` field on the
121+
`LearnerCreditRequestActions` model. This represents the user-facing
122+
status label that is displayed in the UI as a result of an action.
92123
"""
124+
REQUESTED = 'requested'
125+
REMINDED = 'reminded'
126+
APPROVED = 'approved'
127+
ACCEPTED = 'accepted'
128+
DECLINED = 'declined'
129+
REVERSED = 'reversed'
130+
CANCELLED = 'cancelled'
131+
EXPIRED = 'expired'
132+
93133
CHOICES = (
94-
(SubsidyRequestStates.REQUESTED, "Requested"),
95-
(LearnerCreditAdditionalActionStates.REMINDED, "Waiting For Learner"),
96-
(SubsidyRequestStates.APPROVED, "Waiting For Learner"),
97-
(SubsidyRequestStates.ACCEPTED, "Redeemed By Learner"),
98-
(SubsidyRequestStates.DECLINED, "Declined"),
99-
(SubsidyRequestStates.REVERSED, "Refunded"),
100-
(SubsidyRequestStates.CANCELLED, "Cancelled"),
101-
(SubsidyRequestStates.EXPIRED, "Expired"),
134+
(REQUESTED, "Requested"),
135+
(REMINDED, "Waiting For Learner"),
136+
(APPROVED, "Waiting For Learner"),
137+
(ACCEPTED, "Redeemed By Learner"),
138+
(DECLINED, "Declined"),
139+
(REVERSED, "Refunded"),
140+
(CANCELLED, "Cancelled"),
141+
(EXPIRED, "Expired"),
102142
)
103143

104144

enterprise_access/apps/subsidy_request/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from enterprise_access.apps.subsidy_request.constants import (
2323
SUBSIDY_REQUEST_BULK_OPERATION_BATCH_SIZE,
2424
LearnerCreditAdditionalActionStates,
25-
LearnerCreditRequestActionChoices,
25+
LearnerCreditRequestActionTypes,
2626
LearnerCreditRequestActionErrorReasons,
2727
LearnerCreditRequestUserMessages,
2828
SubsidyRequestStates,
@@ -560,7 +560,7 @@ class LearnerCreditRequestActions(TimeStampedModel):
560560
blank=False,
561561
null=False,
562562
db_index=True,
563-
choices=LearnerCreditRequestActionChoices,
563+
choices=LearnerCreditRequestActionTypes.CHOICES,
564564
help_text="The type of action taken on the learner credit request.",
565565
)
566566

@@ -615,7 +615,7 @@ def create_action(
615615
Args:
616616
learner_credit_request (LearnerCreditRequest): The associated learner credit request.
617617
recent_action (str): The type of action taken (must be a valid choice from
618-
LearnerCreditRequestActionChoices).
618+
LearnerCreditRequestActionTypes).
619619
status (str): The status message (must be a valid choice from LearnerCreditRequestUserMessages.CHOICES).
620620
error_reason (str, optional): The error reason if applicable (must be a valid choice
621621
from LearnerCreditRequestActionErrorReasons.CHOICES).

0 commit comments

Comments
 (0)