Skip to content

FINERACT-2994: Reverse savings accruals when a transaction is undone - #6736

Open
samchinmaya wants to merge 1 commit into
apache:developfrom
samchinmaya:FINERACT-2994-savings-undo-accruals
Open

samchinmaya wants to merge 1 commit into
apache:developfrom
samchinmaya:FINERACT-2994-savings-undo-accruals

Conversation

@samchinmaya

Copy link
Copy Markdown
Contributor

Description

Jira: FINERACT-2994

With accrual (periodic) accounting on a savings product, SavingsAccount.deposit() and withdraw() call accrualsForSavingsReverse(), which reverses the accruals dated on or after the new transaction so the accrual job books them again from the new balance. The undo methods (undoTransaction(Long), undoSavingsTransaction(Long), undoTransaction(SavingsAccountTransaction)) only reversed the transaction itself. The accrual job only adds accruals after the last one, so accruals on money that was no longer there stayed in Interest Payable and Interest Expense.

This PR moves the reversal loop into reverseAccrualsFrom(date, backdatedTxnsAllowedTill) (used by accrualsForSavingsReverse() as before) and calls it from the three undo methods with the undone transaction's date (not when the undone transaction is itself an accrual). undoTransaction in SavingsAccountWritePlatformServiceJpaRepositoryImpl already collects the reversed transactions before and after and posts their journal entry reversals, so the reversed accruals get reversal entries.

Tests: new SavingsAccountUndoTransactionAccrualTest (2 tests): undoing a deposit reverses the accruals on and after its date and keeps the earlier one, with the normal and the pivot-date transaction lists. Both fail on the old code; the fineract-savings domain tests pass.

Manual check on a jibBuildTar image of this branch vs apache/fineract:0df2ef786f (develop), PostgreSQL. Savings product with accounting rule 3, 6% nominal annual interest; accounts activated 01 July 2026; "Add Accrual Transactions For Savings" run after each step:

Case develop: payable after undo → after next job this PR expected
Deposit 5000, undo the deposit (balance 0) 96.80 → 96.80 0.00 → 0.00 0.00
Deposit 10000, withdraw 4000 on 01 Aug, undo the withdrawal 136.53 → 136.53 50.84 → 193.54 193.54 (account with the same 10000 and no withdrawal)

Savings control GL = account balance and balanced entries in every step, before and after.

Checklist

  • Write the commit message as per our guidelines
  • 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.
  • Create/update unit or integration tests for verifying the changes made.
  • Follow our 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 (no API change)
  • This PR must not be a "code dump". Large changes can be made in a branch, with assistance. Ask for help on the developer mailing list.
  • If merging this PR resolves a JIRA issue, I will mark that issue as resolved and set "Fix Version/s" appropriately.
  • I followed the AI Policy.

A new deposit or withdrawal reverses the accruals dated on or after it, so
they are booked again from the new balance. Undoing a transaction did not,
and the accrual job only adds accruals after the last one, so accruals on
money that was no longer there stayed in Interest Payable and Interest
Expense. The undo methods now reverse those accruals too.

Assisted-By: claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant