FINERACT-2421: Disbursement charge amount incorrect calculation#5428
Conversation
| @@ -853,8 +853,14 @@ private void update(final LoanCharge loanCharge, final BigDecimal amount, final | |||
| private Money getTotalAllTrancheDisbursementAmount(final Loan loan) { | |||
There was a problem hiding this comment.
The method can be refactored to improve readability and maintainability. Consider:
Flattening the nested conditionals and using early returns to clarify the control flow.
Assigning loan.getDisbursementDetails() to a local variable to avoid repeated calls.
Replacing the manual loop for summing disbursements with a stream-based reduce operation.
Structuring the “sum disbursements” and “fallback principal” paths separately to make the logic clearer.
Optionally, renaming the method to better reflect its behavior.
There was a problem hiding this comment.
Code updated, please review @Aman-Mittal
0c66de4 to
415b61f
Compare
| | Disbursement Charge | false | Disbursement | | % Interest | 0.04 | 0.04 | 0.0 | 0.0 | | ||
| | Disbursement Charge | false | Disbursement | | % Interest | 0.03 | 0.0 | 0.0 | 0.03 | | ||
|
|
||
| @Skip |
There was a problem hiding this comment.
Is this test skipped due to flaky test? just curious
There was a problem hiding this comment.
It was skipped now has been fixed and available for testing
| } | ||
| return amount; | ||
| return Money.zero(loan.getCurrency()); | ||
| } |
There was a problem hiding this comment.
here is suggestion this may be more cleaner
private Money sumMultiDisbursementAmounts(final Loan loan) {
if (!loan.isMultiDisburmentLoan()) {
return Money.zero(loan.getCurrency());
}
final List<LoanDisbursementDetails> disbursements = loan.getDisbursementDetails();
final String currency = loan.getCurrency();
if (loan.isSubmittedAndPendingApproval()) {
return Money.of(currency, loan.getProposedPrincipal());
}
if (loan.isApproved()) {
return Money.of(currency, loan.getApprovedPrincipal());
}
// For open loans or any loans with disbursement details
BigDecimal totalPrincipal = disbursements.stream()
.map(LoanDisbursementDetails::principal)
.reduce(BigDecimal.ZERO, BigDecimal::add);
return Money.of(currency, totalPrincipal);
}
There was a problem hiding this comment.
Done! code updated
f4a5012 to
e923c73
Compare
e923c73 to
76a73c6
Compare
Description
Disbursement charge amount incorrect calculation for full/partial disbursement. Repayment schedule and charges Charges: values are not based on disb amount+interest
FINERACT-2421
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.