Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

FINERACT-3394: Share redemption lock-in check must subtract all prior redemptions - #7192

Open
kccrcodes wants to merge 1 commit into
apache:developfrom
kccrcodes:FINERACT-3394
Open

kccrcodes wants to merge 1 commit into
apache:developfrom
kccrcodes:FINERACT-3394

Conversation

@kccrcodes

Copy link
Copy Markdown
Contributor

Description

Fixes FINERACT-3394.

ShareAccountDataSerializer.validateRedeemRequest works out how many shares are out of lock-in on the redeem date. It looped over the account's transactions and only counted a transaction if transactionDate + lockinPeriod <= redeemDate. That rule is correct for purchases, but it was also applied to redemptions: an earlier redemption was only subtracted from the "can be redeemed" total once a full lock-in period had passed since that redemption. Until then, the shares it already took out were counted as still available, so they could be redeemed a second time out of shares that were still locked.

Example: lock-in of 1 month, 100 shares bought on 1 Jan (unlocked from 1 Feb) and 100 on 1 Mar (locked until 1 Apr). Redeeming 100 on 15 Mar is allowed and uses up every unlocked share. Redeeming 50 more on 20 Mar was accepted, because the 15 Mar redemption wasn't subtracted (15 Mar + 1 month = 15 Apr, which is after 20 Mar). 50 of the 1 Mar shares were redeemed during lock-in.

Changes:

  • Apply the lock-in offset only to approved purchase transactions.
  • Subtract every active, approved redemption dated on or before the redeem date from totalSharesCanBeRedeemed, whatever its age (unlocked purchases minus all prior redemptions).
  • The existing totalSharesPurchasedBeforeRedeem check is unchanged, including its handling of approved purchases and redemptions. Pending and rejected transactions are still ignored, because isPurchasTransaction() and isRedeemTransaction() already require APPROVED, and inactive transactions are still skipped by isActive().

Added ShareAccountRedeemLockinTest, a plain JUnit + Mockito unit test with real ShareAccountTransaction objects:

  • secondRedemptionCannotDipIntoSharesStillInLockin reproduces the bug above and now fails with validation.msg.sharesaccount.cannot.be.redeemed.due.to.lockinperiod.
  • firstRedemptionOfUnlockedSharesIsStillAllowed is the control: the first 100-share redemption on 20 Mar is still accepted.
  • oldRedemptionIsStillSubtractedFromSharesThatCanBeRedeemed and remainingUnlockedSharesAfterOldRedemptionCanStillBeRedeemed cover a redemption more than one lock-in period old (50 shares on 1 Feb): redeeming 100 more on 20 Mar is refused, redeeming the remaining 50 is still allowed.

Without the fix, the first of those four tests fails (Expected PlatformApiDataValidationException to be thrown, but nothing was thrown) and the other three pass. With the fix, all four pass. I also ran the nearby share-account unit tests (ShareAccountDataSerializerTest, ShareAccountUndoApprovalAndRejectStatusTest, ShareAccountRepositoryWrapperTest); 32 tests in total, all passing. I didn't run the integration suite locally.

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 (N/A: no API shape change; an invalid redeem now correctly returns 400)
  • 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.

Copilot AI balanced review requested due to automatic review settings December 5, 2026 17:11

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@kccrcodes

Copy link
Copy Markdown
Contributor Author

Re-signed the commit (now verified). Could a committer approve the workflow run when you have a moment? Thanks!

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.

2 participants