ImalkaPerera opened a new pull request, #6764:
URL: https://github.com/apache/fineract/pull/6764

   ## Description
   
   JIRA: https://issues.apache.org/jira/browse/FINERACT-3012
   
   `SavingsAccount.resetFreeChargeDaysCount()` passed the arguments to 
`ChronoUnit.DAYS.between` in reverse order (`DAYS.between(businessDate, 
activatedOnDate)` and `DAYS.between(businessDate, resetDate)`). Because 
`DAYS.between(start, end)` returns `end - start`, the result was always zero or 
negative.
   
   This matters because `restartCountFrequency` must be greater than zero, so 
`totalDays < restartPeriod` was always true and `discountCharge()` (the only 
code that restarts the count) was never reached. For a withdrawal-fee charge 
with free withdrawals enabled and a non-MONTHS restart period, the 
free-withdrawal count never restarted: once the free withdrawals were used, 
every later withdrawal was charged the fee indefinitely.
   
   This is a regression from the Date to LocalDate refactor (`1db8ef46fc`, 
2022). Before it, the code computed `businessDate - activatedOnDate`, which is 
positive.
   
   Example: flat fee 10, 2 free withdrawals, restart every 7 DAYS, account 
activated 2026-01-01. Withdrawals on 01-02 and 01-03 are free, and 01-04 is 
charged 10 (correct). A withdrawal on 01-15 (14 days later) was charged 10; it 
should be free and restart the count to 1.
   
   ### Fix
   
   - Swap the arguments in both calls so the start date comes first: 
`DAYS.between(activatedOnDate, businessDate)` and `DAYS.between(resetDate, 
businessDate)`.
   - Nothing else changes. The MONTHS branch is untouched.
   
   ### Tests
   
   New `SavingsAccountFreeWithdrawalResetTest` (JUnit 5, 2 tests):
   - DAYS: two free withdrawals, one charged, then a withdrawal after the 
restart period is free, the count restarts to 1 and the reset date is set
   - MONTHS: the same flow, as a control for the existing branch
   
   The DAYS test fails on unmodified `develop` (`expected: 0 but was: 10.00`) 
and passes with the fix. The MONTHS test passes both ways. `./gradlew 
:fineract-savings:test` (79 tests) and `./gradlew 
:fineract-savings:spotlessCheck` pass locally.
   
   The test calls the private withdrawal-fee step (`payWithdrawalFee`) via 
reflection, to avoid the unrelated validations in `withdraw()`. Happy to change 
this if reviewers prefer.
   
   Note: verified with unit tests, not with an end-to-end HTTP run. WEEKS, 
YEARS and an unset `countFrequencyType` share this branch, so they now restart 
too but are still counted in days. That unit mismatch, and measuring from the 
business date rather than the transaction date, are out of scope and will be 
handled separately.
   
   
   ## Checklist
   
   - [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).
   - [x] 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 (N/A, no API change)
   - [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]

Reply via email to