Repository navigation
Fix: Round amount_finaid() to nearest cent to unblock percentage-aid payments - #6084
Open
Shresth-14 wants to merge 4 commits into
Open
Shresth-14 wants to merge 4 commits into
Shresth-14 wants to merge 4 commits into
Conversation
…learning-unlimited#6055) Percentage-based financial aid grants on non-whole-dollar amounts (e.g. 25% of $47.50 = $11.875) produce fractional cents in amount_finaid(). This makes amount_due() a non-integer number of cents, causing the Stripe payment flow to fail with an 'inconsistent_amount' error because int(amount_due * 100) disagrees with Decimal(amount_due) * 100. Round amount_finaid() using ROUND_HALF_UP per maintainer guidance so that all downstream accounting calculations resolve to whole cents. Add regression tests covering fractional cents and half-cent rounding.
Comment on lines
+495
to
+504
| # $47.50 at 25% = $11.875 — this is the exact half-cent boundary. | ||
| LineItemType.objects.filter( | ||
| program=self.program, text='Program admission' | ||
| ).update(amount_dec=Decimal('47.50')) | ||
|
|
||
| self.iac.set_finaid_params(None, 25) | ||
| finaid = self.iac.amount_finaid() | ||
| # ROUND_HALF_UP: $11.875 → $11.88 (rounds up, not to $11.88 via ROUND_HALF_EVEN too, | ||
| # but importantly NOT $11.87 as a truncation or floor would give). | ||
| self.assertEqual(finaid, Decimal('11.88')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Percentage-based financial aid grants on non-whole-dollar amounts (e.g. 25% of $47.50 = $11.875) produce fractional cents in
amount_finaid(). This makesamount_due()a non-integer number of cents, causing the Stripe payment flow to fail with aninconsistent_amounterror becauseint(amount_due * 100)disagrees withDecimal(amount_due) * 100.Round
amount_finaid()usingROUND_HALF_UPper maintainer guidance so that all downstream accounting calculations resolve to whole cents. Add regression tests covering fractional cents and half-cent rounding.Description
When financial aid is awarded as a percentage discount (e.g., 25%) and the program cost or item cost is not a whole-dollar amount (e.g., $47.50),
IndividualAccountingController.amount_finaid()calculated fractional-cent aid amounts without rounding ($11.875).This produced a cascading failure when the student attempted to pay online:
amount_due()returned fractional cents ($35.625).payonline()computed the Stripe form amount asint(Decimal('35.625') * 100) = 3562($35.62).charge_payment()verified this againstDecimal(iac.amount_due()) * 100 = 3562.5.3562 ≠ 3562.5,charge_payment()aborted withinconsistent_amount, completely blocking the student from completing payment.link_paid_transfers()would fail due to the transfers not summing to the target price ($35.62 + $11.875 = $47.495 ≠ $47.50).Solution
IndividualAccountingController.amount_finaid()inesp/esp/accounting/controllers.pyto round the final aid amount to whole cents using.quantize(Decimal('0.01'), rounding=ROUND_HALF_UP).ROUND_HALF_UP: half a cent or more rounds up to the student's benefit; less than half a cent rounds down).esp/esp/accounting/tests/test_models.pyverifying:ROUND_HALF_UP).Related Issue
Closes #6055
Type of Change
Testing
Testing Details:
IndividualAccountingControllerTest.test_amount_finaid_percentage_rounded_to_centsIndividualAccountingControllerTest.test_amount_finaid_half_cent_rounds_upIndividualAccountingControllerTest.test_amount_finaid_percentage_and_dollar_cap_rounded_to_centsint(due * 100) == int(Decimal(due) * 100) == 3562).AI Disclosure
This pull request was prepared with the assistance of an AI assistant (Google Antigravity) to identify root cause code paths, implement the rounding fix following maintainer discussion on #6055, and write regression tests. All changes and tests have been reviewed and verified.
Checklist