Senesh Perera created FINERACT-3031:
---------------------------------------

             Summary: Free withdrawal count restarts too early when restart 
frequency is WEEKS or YEARS
                 Key: FINERACT-3031
                 URL: https://issues.apache.org/jira/browse/FINERACT-3031
             Project: Apache Fineract
          Issue Type: Bug
          Components: Charges, Savings
    Affects Versions: 1.16.1
            Reporter: Senesh Perera
            Assignee: Senesh Perera


h3. Problem

For a savings withdrawal fee with free withdrawals enabled, 
{{SavingsAccount.resetFreeChargeDaysCount}} decides when the free withdrawal 
count restarts.

The code only checks for MONTHS:

{code:java}
if (charge.getRestartFrequencyEnum() == 2) { // months
    ...
} else { // days
    ...
}
{code}

All other values go to the "days" branch. This includes WEEKS (1) and YEARS 
(3). So "restart every 1 week" works like "restart every 1 day". "Restart every 
1 year" also works like "restart every 1 day".

h3. Why this can happen

* The API does not limit {{countFrequencyType}} (see 
{{ChargeDefinitionCommandFromApiJsonDeserializer}}).
* The Swagger example for this field is {{1}} (WEEKS).
* The comment on {{getRestartFrequencyEnum}} says "enum day/week/month".
* The {{== 2}} check came from FINERACT-1374. WEEKS and YEARS were never 
handled.

h3. Steps to reproduce

# Create a withdrawal fee charge: flat amount 10, free withdrawals enabled, 2 
free withdrawals, restart every 1 WEEK.
# Activate a savings account with this charge on 2026-01-01.
# Withdraw on 2026-01-02, 2026-01-03 and 2026-01-04.

h3. Expected result

The first 2 withdrawals are free. The third withdrawal is charged 10, because 
less than 1 week has passed.

h3. Actual result

The third withdrawal is also free (fee 0). The count restarts every day, so the 
fee is never charged.

h3. Impact

The free withdrawal count restarts much earlier than configured. The bank 
collects less fee income than it should. This only affects charges that have 
free withdrawals enabled and a restart type of WEEKS or YEARS.

h3. Proposed fix

In the non-month branch, calculate the restart date by frequency type:

* WEEKS: {{restartFrom.plusWeeks(period)}}
* YEARS: {{restartFrom.plusYears(period)}}
* DAYS: {{restartFrom.plusDays(period)}}

Then compare the result with the business date. For DAYS, the behavior stays 
the same as before.

h3. Tests

Add unit tests to {{SavingsAccountFreeWithdrawalResetTest}}:

* WEEKS, period not elapsed
* WEEKS, period elapsed
* YEARS, period not elapsed
* YEARS, period elapsed

Before the fix, these tests fail. After the fix, all tests pass, including the 
existing DAYS and MONTHS tests.

h3. Related

* FINERACT-3012 fixed the DAYS part (PR #6764). It mentioned WEEKS and YEARS as 
a separate topic.
* I found no other ticket or PR for this problem.

h3. Out of scope (possible separate tickets)

* WHOLE_TERM (4), INVALID (5) and null also go to the days branch. Not tested.
* {{Charge.update}} converts {{countFrequencyType}} with 
{{ChargeTimeType.fromInt}} instead of {{PeriodFrequencyType}}. Values 0-16 map 
correctly, but other values become 0 (DAYS). Not tested.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to