Skip to content

FINERACT-2455: WC - Undo disbursal reverses the discount fee and amortization journal entries - #6457

Merged
adamsaghy merged 2 commits into
apache:developfrom
openMF:FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries
Sep 25, 2026
Merged

adamsaghy merged 2 commits into
apache:developfrom
openMF:FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries

Conversation

@somasorosdpc

@somasorosdpc somasorosdpc commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

depends on #6458

Description

Describe the changes made and why they were made. (Ignore if these details are present on the associated Apache Fineract JIRA ticket.)

Checklist

Please make sure these boxes are checked before submitting your pull request - thanks!

  • 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
  • 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.

Your assigned reviewer(s) will follow our guidelines for code reviews.

@somasorosdpc
somasorosdpc force-pushed the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch 5 times, most recently from 198d6a0 to 2638919 Compare September 18, 2026 12:30
@adamsaghy
adamsaghy marked this pull request as ready for review September 21, 2026 14:36
@somasorosdpc
somasorosdpc force-pushed the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch 2 times, most recently from ba48f33 to 24eef2c Compare September 23, 2026 11:04

@galovics galovics left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The core fix looks right. reverseDisbursementTransactionAndResetBalance now reverses the live journal entries of every transaction it reverses (disbursement, discount fee, discount fee adjustment, amortization, amortization adjustment, accruals) instead of only the disbursement and accruals. It's safe over previously undone transactions because findJournalEntries filters on reversed=false, so nothing is double-mirrored, and skipping already-reversed transactions also fixes reversedOnDate/reversalExternalId being overwritten on ones undone earlier (C106725 covers it). Re-disbursal after undo starts clean. A few things I'd want before merge:

  • The gate moved into the processor with no unit test. isAccountingDisabled actually checks "the rule is not ACC_DEF_REV_AM", which is the same as "accounting disabled" only while this is the sole WorkingCapitalLoanAccountingProcessor implementation. More importantly, this PR deleted verify(accountingProcessor, never()).postJournalEntries(...) from WorkingCapitalLoanRecoveryPaymentWriteServiceTest - the only test of the "no accounting, no JEs" path - and nothing replaced it. Please add a unit test in the processor test with a non-accrual rule asserting nothing is posted; every caller depends on this gate now. And the guard move is only half done: the amortization service, the transaction processor, credit balance refund and the accrual service still check at the call site, so pick one layer or document the processor check as a safety net. It's also scope creep - the fix is ~5 lines, the refactor touches charge-off, write-off, recovery, reprocessing and amortization; I'd split it.
  • peek for side effects (WorkingCapitalLoanWritePlatformServiceImpl ~L1302): mutation inside Stream.peek (Sonar S3864), with trailing comments the formatter wrapped into a broken fragment. A plain loop reads better. The comment below it ("Reverse the journal entries of any charge accrual...") is now stale - that block only publishes the accrual adjustment events.
  • No reversal events for the reversed DISCOUNT_FEE / DISCOUNT_FEE_ADJUSTMENT / amortization transactions (only accruals get one), unlike reverseLiveCorrections in the amortization service. Pre-existing, but this is the place to fix it, or ticket it.
  • Test gaps: C106721-C106725 assert journal entries after undo, which is the right level, but the scenario named for the "amortization adjustment journal entries" only asserts the reversed DISCOUNT_FEE_ADJUSTMENT entries - that's the path where #6281 had the asymmetry, so assert the amortization adjustment entries too. Also no scenario re-disburses after an undo with a discount fee, and no unit test for the undo loop itself.

Housekeeping: squash the two commits, and drop the duplicate loan.getLoanProduct() stub in the processor test.

Recommendation: COMMENT

@adamsaghy
adamsaghy force-pushed the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch from 24eef2c to 1640f73 Compare September 24, 2026 21:36
somasorosdpc and others added 2 commits September 25, 2026 12:12
…tization journal entries

Co-authored-by: Adam Saghy <adamsaghy@gmail.com>
…rsal reverses the discount fee and amortization journal entries

Co-authored-by: Adam Saghy <adamsaghy@gmail.com>
@adamsaghy
adamsaghy force-pushed the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch from 1640f73 to edd88a0 Compare September 25, 2026 11:13
@somasorosdpc
somasorosdpc force-pushed the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch from edd88a0 to d05cd7a Compare September 25, 2026 11:42
@adamsaghy
adamsaghy force-pushed the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch from d05cd7a to edd88a0 Compare September 25, 2026 11:51

@adamsaghy adamsaghy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@adamsaghy
adamsaghy merged commit 7f8b0c3 into apache:develop Sep 25, 2026
167 of 188 checks passed
@adamsaghy
adamsaghy deleted the FINERACT-2455/wc-undo-disbursement-reverses-discount-fee-and-amortization-journal-entries branch September 25, 2026 12:44
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.

4 participants