-
Notifications
You must be signed in to change notification settings - Fork 2.2k
FINERACT-2354: fix error while do re-amortization on disbursement day #5314
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
FINERACT-2354: fix error while do re-amortization on disbursement day #5314
Conversation
| Money totalOverDueInterest = Money.zero(currency); | ||
|
|
||
| if (previousInstallments.isEmpty()) { | ||
| loanTransaction.resetDerivedComponents(); | ||
| loanTransaction.updateComponentsAndTotal(totalOverDuePrincipal, totalOverDueInterest, Money.zero(currency), | ||
| Money.zero(currency)); | ||
| if (loanTransaction.isNotReversed()) { | ||
| loanTransaction.reverse(); | ||
| loanTransaction.manuallyAdjustedOrReversed(); | ||
| } | ||
| return; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please help me understand what this logic is for?
Also seems reused multiple times, we might wanna extract this into a method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic handles an edge case where re-amortization is requested on disbursement day. At this point, previousInstallments (installments with due date ≤ transaction date) is empty because all installments are scheduled in the future.
Without this guard, calling previousInstallments.getLast() throws NoSuchElementException causing a 500 error.
The fix gracefully handles this by:
- Setting transaction amounts to zero
- Reversing the transaction (since there's nothing to re-amortize)
- Returning early
This is consistent with the existing logic that reverses the transaction when both principal and interest are zero
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@budaidev I see. Thanks, then just extract the common logic and reuse it! ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, there is 1 thought... if there is no any reamortizable amount, maybe we should just throw a domain rule exception and explain, Reamortization cannot be executed, hence no overdue amount.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I modified it so we should throw an error in these cases
adamsaghy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kindly see my concerns!
d70c702 to
a8efa41
Compare
a8efa41 to
1767b72
Compare
|
@adamsaghy I have made some test changes according the validation we discussed here |
Description
Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)
Checklist
Please make sure these boxes are checked before submitting your pull request - thanks!
Your assigned reviewer(s) will follow our guidelines for code reviews.