Skip to content

Commit 320bfe8

Browse files
authored
fix: fix allocation math (#373)
2 parents cbafbbc + 5838f29 commit 320bfe8

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

enterprise_access/apps/api/v1/tests/test_allocation_view.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -714,10 +714,11 @@ def test_allocate_too_much_subsidy_spend_e2e(
714714
'admin_users': [{'email': '[email protected]'}],
715715
}
716716

717-
subsidy_balance = 300
717+
subsidy_balance = 1
718718
mock_subsidy_balance.return_value = subsidy_balance
719+
# NOTE johnnagro this figure is no longer used in the math
719720
mock_aggregates_for_policy.return_value = {
720-
'total_quantity': (subsidy_balance - 1) * -1,
721+
'total_quantity': 0,
721722
}
722723

723724
allocate_url = _allocation_url(self.assigned_learner_credit_policy.uuid)
@@ -795,10 +796,11 @@ def test_allocate_too_much_existing_allocation_e2e(
795796
'admin_users': [{'email': '[email protected]'}],
796797
}
797798

798-
subsidy_balance = 300
799+
subsidy_balance = 1
799800
mock_subsidy_balance.return_value = subsidy_balance
801+
# TODO johnnagro this figure is no longer used in the math
800802
mock_aggregates_for_policy.return_value = {
801-
'total_quantity': (subsidy_balance - 1) * -1,
803+
'total_quantity': 0,
802804
}
803805

804806
allocate_url = _allocation_url(self.assigned_learner_credit_policy.uuid)

enterprise_access/apps/subsidy_access_policy/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,15 +1275,15 @@ def can_allocate(self, number_of_learners, content_key, content_price_cents):
12751275
# allocate won't exceed the remaining balance of the related subsidy.
12761276
subsidy_balance = self.subsidy_balance()
12771277
if self.content_would_exceed_limit(
1278-
total_allocated_and_spent_cents,
1278+
total_allocated_assignments_cents,
12791279
subsidy_balance,
12801280
positive_total_price_cents,
12811281
):
12821282
logger.info(
12831283
f'content_would_exceed_limit function: '
12841284
f'subsidy_uuid={self.subsidy_uuid}, '
12851285
f'policy_uuid={self.uuid},'
1286-
f'total_allocated_and_spent_centers={total_allocated_and_spent_cents}, '
1286+
f'total_allocated_assignments_cents={total_allocated_assignments_cents}, '
12871287
f'subsidy_balance={subsidy_balance}, '
12881288
f'positive_total_price_cents={positive_total_price_cents}, '
12891289
)

enterprise_access/apps/subsidy_access_policy/tests/test_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ def test_can_allocate_not_enough_subsidy_balance(self):
11361136
},
11371137
}
11381138
self.mock_subsidy_client.list_subsidy_transactions.return_value = transactions_for_policy
1139-
self.mock_assignments_api.get_allocated_quantity_for_configuration.return_value = -500
1139+
self.mock_assignments_api.get_allocated_quantity_for_configuration.return_value = -1000
11401140

11411141
# The balance of the subsidy is just a bit less
11421142
# than the amount to potentially allocated, e.g.

0 commit comments

Comments
 (0)