samchinmaya opened a new pull request, #6661: URL: https://github.com/apache/fineract/pull/6661
## Description JIRA: [FINERACT-2952](https://issues.apache.org/jira/browse/FINERACT-2952) When a savings withdrawal that charged a withdrawal fee was undone or adjusted, the fee was often not reversed: - **Undo:** the withdrawal was reversed but the fee stayed, so the customer kept paying a fee for a withdrawal that no longer exists. - **Adjust:** the old fee stayed and a new fee was charged for the new amount, so one withdrawal was charged twice. The API returned 200 in both cases. `undoTransaction()` and `adjustSavingsTransaction()` in `SavingsAccountWritePlatformServiceJpaRepositoryImpl` looked for the fee at `transactionId + 1`. The withdrawal and its fee are saved together, and the fee often gets the lower id (both orders show up on the same build), so the lookup then found nothing, or a different transaction. Change: - New `undoWithdrawalFee()`, used by both methods. It finds the fee through the `refNo` it shares with the withdrawal (set since FINERACT-1642; `findByRefNo` is already used by the bulk `reverse` command) and only undoes fees of the same account that are not reversed yet. - Transactions without a `refNo` (saved before it existed) keep the old `transactionId + 1` lookup. - 3 unit tests in `SavingsAccountWritePlatformServiceJpaRepositoryImplTest`: a fee with the lower id is found by `refNo`; fees of other accounts and reversed fees are skipped; without a `refNo` the next transaction is used. Verification: - `SavingsAccountWritePlatformServiceJpaRepositoryImplTest` passes (14/14). `spotlessJavaCheck` and `checkstyleTest` pass. - Real API on PostgreSQL. Savings account with a 1% withdrawal fee, balance 1000, withdraw 100 (fee 1.00), then undo it or adjust it to 50. Fresh client and account for each case: | Case | Expected balance | develop (ddb1ca0), 5 runs | this branch, 12 runs | |---|---|---|---| | Undo the withdrawal | 1000.00 | 999.00 in 3 runs (fee kept) | 1000.00 every run | | Adjust it to 50 | 949.50 | 948.50 in 1 run (old fee kept, new 0.50 fee added) | 949.50 every run | In the runs on this branch the fee got the lower id several times, which is the case that failed before. ## 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. - [x] I followed the [AI Policy](https://github.com/apache/fineract/blob/develop/CONTRIBUTING.md#ai-policy). Your assigned reviewer(s) will follow our [guidelines for code reviews](https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide). -- 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]
