samchinmaya opened a new pull request, #6684: URL: https://github.com/apache/fineract/pull/6684
## Description JIRA: [FINERACT-2966](https://issues.apache.org/jira/browse/FINERACT-2966) After a loan is written off, each recovery payment should add to the loan summary's `totalRecovered` (`m_loan.total_recovered_derived`). It always lagged one payment behind: the payment just made was never counted. FINERACT-2234 (cb6a15c3d2) changed `LoanBalanceService.calculateTotalRecoveredPayments` to sum the recovery payments with `LoanTransactionRepository.calculateTotalRecoveryPaymentAmount`. The summary is refreshed in `updateLoanSummaryDerivedFields` with `FlushModeType.COMMIT`, and `LoanAccountDomainServiceJpa.makeRepayment` only saves the new recovery transaction after that refresh, so the query could not see it. Change: - `calculateTotalRecoveredPayments` sums `isRecoveryRepayment()` transactions from `loan.getLoanTransactions()` again, like `calculateTotalOverpayment` next to it. That list includes the unsaved transaction, and `isRecoveryRepayment()` already skips reversed ones. - The repository query had no other caller, so it is removed, together with the now unused `LoanTransactionRepository` field of `LoanBalanceService`. - New `LoanBalanceServiceTest` (3 tests): an unsaved recovery payment is counted, reversed and other transactions are not, no recovery payments gives zero. Verification: - `LoanBalanceServiceTest` passes (3/3). `spotlessJavaApply`, `checkstyleMain`, `checkstyleTest` and `:fineract-provider:compileJava` pass. - Real API on PostgreSQL: loan of 1000 written off, then recovery payments of 100, 50 and 25, reading `summary.totalRecovered` after each: | After recovery of | Expected | develop (7f45e30678) | this branch | |---|---|---|---| | 100 | 100 | 0 | 100 | | 50 | 150 | 100 | 150 | | 25 | 175 | 150 | 175 | ## Checklist Please make sure these boxes are checked before submitting your pull request - thanks! - [x] Write the commit message as per [our guidelines](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#pull-requests) - [x] Acknowledge that we will not review PRs that are not passing the build _("green")_ - it is your responsibility to get a proposed PR to pass the build, not primarily the project's maintainers. - [x] Create/update [unit or integration tests](https://fineract.apache.org/docs/current/#_testing) for verifying the changes made. - [x] Follow our [coding conventions](https://cwiki.apache.org/confluence/display/FINERACT/Coding+Conventions). - [ ] Add required Swagger annotation and update API documentation at fineract-provider/src/main/resources/static/legacy-docs/apiLive.htm with details of any API changes - [x] [This PR must not be a "code dump"](https://cwiki.apache.org/confluence/display/FINERACT/Pull+Request+Size+Limit). Large changes can be made in a branch, with assistance. Ask for help on the [developer mailing list](https://fineract.apache.org/#contribute). - [x] If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
