Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: change which reasons are selected for a non-redeemable policy #224

Merged
merged 1 commit into from
Jul 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions enterprise_access/apps/subsidy_access_policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,13 @@ def will_exceed_spend_limit(self, content_key, content_metadata=None):
def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
"""
Check that a given learner can redeem the given content.
The ordering of each conditional is intentional based on an expected
error message to be shown based on the learners state at the time of
accessing the CourseAbout page in FE-app-learner-portal focusing on the
user state, catalog state based on content key, then subsidy/policy state
based on whether they are active and have spend available for the requested
content.


Returns:
3-tuple of (bool, str, list of dict):
Expand All @@ -335,14 +342,6 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
active_subsidy = subsidy_can_redeem_payload.get('active', False)
existing_transactions = subsidy_can_redeem_payload.get('all_transactions', [])

# inactive subsidy
if not active_subsidy:
return (False, REASON_SUBSIDY_EXPIRED, [])

# inactive policy
if not self.active:
return (False, REASON_POLICY_EXPIRED, [])

# learner not associated to enterprise
if not skip_customer_user_check:
if not self.lms_api_client.enterprise_contains_learner(self.enterprise_customer_uuid, lms_user_id):
Expand All @@ -356,6 +355,16 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
if not content_metadata:
return (False, REASON_CONTENT_NOT_IN_CATALOG, existing_transactions)

# TODO: Add Course Upgrade/Registration Deadline Passed Error here

# inactive subsidy
if not active_subsidy:
return (False, REASON_SUBSIDY_EXPIRED, [])

# inactive policy
if not self.active:
return (False, REASON_POLICY_EXPIRED, [])

# can_redeem false from subsidy
if not subsidy_can_redeem_payload.get('can_redeem', False):
return (False, REASON_NOT_ENOUGH_VALUE_IN_SUBSIDY, existing_transactions)
Expand Down
Loading