Skip to content

FINERACT-2181: Fix in advance paydate calculation#4798

Merged
adamsaghy merged 1 commit intoapache:developfrom
openMF:FINERACT-2181-Loan-prepay-template-gives-wrong-amount-in-case-of-Interest-Recalculation-loans
Jul 7, 2025
Merged

FINERACT-2181: Fix in advance paydate calculation#4798
adamsaghy merged 1 commit intoapache:developfrom
openMF:FINERACT-2181-Loan-prepay-template-gives-wrong-amount-in-case-of-Interest-Recalculation-loans

Conversation

@Cocoa-Puffs
Copy link
Copy Markdown
Contributor

@Cocoa-Puffs Cocoa-Puffs commented Jun 24, 2025

Description

Rest frequency type and pre close interest calculation strategy defined in LoanInterestRecalculationDetails can make the prepayment api and payment allocation inconsistent.

if restFrequencyType == DAILY and preCloseInterestCalculationStrategy == TILL_PRE_CLOSURE_DATE then no problem.
if restFrequencyType == SAME_AS_REPAYMENT_PERIOD and preCloseInterestCalculationStrategy == TILL_REST_FREQUENCY_DATE then again, no problem.

But if we mix these settings: restFrequencyType == DAILY and preCloseInterestCalculationStrategy == TILL_REST_FREQUENCY_DATE or restFrequencyType == SAME_AS_REPAYMENT_PERIOD and preCloseInterestCalculationStrategy == TILL_PRE_CLOSURE_DATE

Then currently the prepay api calculates the amount payable until the end of the current period because of the pre close setting, but during payment allocation we go into overpayment, because the interest between the transaction date and the related installment periods due date will not be taken into account.

In this PR I attempt to make the functionality consistent, by calculating if the current repayment transaction fully pays off the outstanding amount of the loan, and in the case that it does even if we have daily interest recalculation set it will still allocate the remainder of the period, like if it was set to 'same as repayment period'

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 https://github.com/apache/fineract/#pull-requests
  • 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 coding conventions at https://cwiki.apache.org/confluence/display/FINERACT/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
  • Submission is not a "code dump". (Large changes can be made "in repository" via a branch. Ask on the developer mailing list for guidance, if required.)

FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.

@Cocoa-Puffs Cocoa-Puffs force-pushed the FINERACT-2181-Loan-prepay-template-gives-wrong-amount-in-case-of-Interest-Recalculation-loans branch 5 times, most recently from b23a782 to 7bd8a24 Compare June 27, 2025 14:00
@Cocoa-Puffs Cocoa-Puffs marked this pull request as ready for review July 1, 2025 11:09
case SAME_AS_REPAYMENT_PERIOD ->
recalculationDetails.getPreCloseInterestCalculationStrategy().calculateTillRestFrequencyEnabled();
case WEEKLY -> throw new IllegalStateException("Unexpected RecalculationFrequencyType: WEEKLY");
case MONTHLY -> throw new IllegalStateException("Unexpected RecalculationFrequencyType: MONTHLY");
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.

I see the issue here - runtime exceptions are not good. Could we add validation during loan product creation to prevent selecting WEEKLY or MONTHLY frequency?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have added the validation to LoanProductDataValidator, however I've kept the exceptions just to be sure we aren't processing loans we are not supporting.

… prepay api and payment allocation inconsistent
@Cocoa-Puffs Cocoa-Puffs force-pushed the FINERACT-2181-Loan-prepay-template-gives-wrong-amount-in-case-of-Interest-Recalculation-loans branch from 7bd8a24 to c833987 Compare July 4, 2025 14:13
Copy link
Copy Markdown
Contributor

@adamsaghy adamsaghy left a comment

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 df995bc into apache:develop Jul 7, 2025
39 checks passed
@adamsaghy adamsaghy deleted the FINERACT-2181-Loan-prepay-template-gives-wrong-amount-in-case-of-Interest-Recalculation-loans branch July 7, 2025 15:04
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.

3 participants