Skip to content

Commit

Permalink
fix: unsupported operand type for remaining balance
Browse files Browse the repository at this point in the history
remove int from transaction count

incorporated feedback

incorporated feedback round two

incorporated feedback round 3
  • Loading branch information
Sameen Fatima authored and Sameen Fatima committed Sep 15, 2023
1 parent 46074dc commit 6dc80aa
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions enterprise_access/apps/subsidy_access_policy/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,14 +721,18 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
return (True, None, existing_redemptions)

def credit_available(self, lms_user_id=None):
if self.remaining_balance_per_user(lms_user_id) > 0:
return True
return False
remaining_balance_per_user = self.remaining_balance_per_user(lms_user_id)
return (remaining_balance_per_user is not None) and remaining_balance_per_user > 0

def remaining_balance_per_user(self, lms_user_id=None):
"""
Returns the remaining redeemable credit for the user.
Returns None if `per_learner_enrollment_limit` is not set.
"""
if self.per_learner_enrollment_limit is None:
return None
if self.per_learner_enrollment_limit <= 0:
return 0
existing_transaction_count = len(self.transactions_for_learner(lms_user_id)['transactions'])
return self.per_learner_enrollment_limit - existing_transaction_count

Expand Down Expand Up @@ -777,12 +781,18 @@ def can_redeem(self, lms_user_id, content_key, skip_customer_user_check=False):
return (True, None, existing_redemptions)

def credit_available(self, lms_user_id=None):
return self.remaining_balance_per_user(lms_user_id) > 0
remaining_balance_per_user = self.remaining_balance_per_user(lms_user_id)
return (remaining_balance_per_user is not None) and remaining_balance_per_user > 0

def remaining_balance_per_user(self, lms_user_id=None):
"""
Returns the remaining redeemable credit for the user.
Returns None if `per_learner_spend_limit` is not set.
"""
if self.per_learner_spend_limit is None:
return None
if self.per_learner_spend_limit <= 0:
return 0
spent_amount = self.transactions_for_learner(lms_user_id)['aggregates'].get('total_quantity') or 0
return self.per_learner_spend_limit - spent_amount

Expand Down

0 comments on commit 6dc80aa

Please sign in to comment.