Skip to content

Conversation

@somasorosdpc
Copy link
Contributor

Description

  • introduce Payment Waiver transaction type
  • add integrtion tests
  • refactor code under the callstack of payment waiver command handler

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.

@somasorosdpc somasorosdpc changed the title Fineract 2092/new transaction type payment waiver Fineract-2092: new transaction type payment waiver Jun 13, 2024
@somasorosdpc somasorosdpc changed the title Fineract-2092: new transaction type payment waiver FINERACT-2092: new transaction type payment waiver Jun 13, 2024
@somasorosdpc somasorosdpc marked this pull request as ready for review June 14, 2024 07:07
@adamsaghy adamsaghy changed the title FINERACT-2092: new transaction type payment waiver FINERACT-2092: New transaction type payment waiver Jun 14, 2024
@somasorosdpc somasorosdpc force-pushed the FINERACT-2092/new_transaction_type_payment-waiver branch from 79e3da2 to 5269d8e Compare June 14, 2024 09:12

@Transactional
@Override
public CommandProcessingResult makeLoanRepaymentWithPaymentWaiver(final JsonCommand command) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We might wanna rename this to makePaymentWaiver

return isChronologicallyLatestRepaymentOrWaiver;
}

LoanTransaction assembleTransactionAndCalculateChanges(Loan loan, JsonCommand command, Map<String, Object> changes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might wanna move this into a LoanTransactionAssembler.

txnExternalId, null);
}

ChangedTransactionDetail assembleUpdatedLoan(Loan loan, LoanTransaction newPaymentWaiverTransaction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You might wanna rename this something more descriptive: example: recalculateLoanWithPaymentWaiverTxn

loan = saveAndFlushLoanWithDataIntegrityViolationChecks(loan);

// Save Note
if (StringUtils.isNotBlank(noteText)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to call the createNote(noteText, loan) instead?


// Save changedTransactionDetail if exists

if (changedTransactionDetail != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to extract into a method this logic?

changes.put("paymentTypeId", command.longValueOfParameterNamed("paymentTypeId"));

if (StringUtils.isNotBlank(noteText)) {
changes.put("note", noteText);
Copy link
Contributor

@adamsaghy adamsaghy Jun 14, 2024

Choose a reason for hiding this comment

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

Is there any logic which requires the note to be in the changes array?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't have any build-in logic on it. But as I see we send back it in the response, and other repayment type returns it, I think, we should keep it in the changes set to keep uniform response values.

doPostLoanTransactionChecks(loan, newPaymentWaiverTransaction.getTransactionDate(), defaultLoanLifecycleStateMachine);

// Payment allocation calculates the new total principal repaid and it should be validated after recalculation
if (loan.getLoanProduct().isMultiDisburseLoan()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we move this out from this method and be called after assembleTransactionAndCalculateChanges ?

}
}
}
if (reprocess) {
Copy link
Contributor

@adamsaghy adamsaghy Jun 14, 2024

Choose a reason for hiding this comment

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

Would it make sense to extract it into a new method?

final LoanRepaymentScheduleInstallment currentInstallment = loan
.fetchLoanRepaymentScheduleInstallment(newPaymentWaiverTransaction.getTransactionDate());

boolean reprocess = true;
Copy link
Contributor

@adamsaghy adamsaghy Jun 14, 2024

Choose a reason for hiding this comment

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

Would it make sense to extract it into a new method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As I see, the logic calculates reprocess flag and also does repayment schedule calculation in some cases which strongly connects the main logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe it would be better to move this where ever we storing the note. Thoughts?

Copy link
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.

Please kindly check my review!

@somasorosdpc somasorosdpc force-pushed the FINERACT-2092/new_transaction_type_payment-waiver branch 8 times, most recently from 8aaa1ec to 45b0c6d Compare June 19, 2024 08:51
@somasorosdpc somasorosdpc changed the title FINERACT-2092: New transaction type payment waiver FINERACT-2092: New transaction type interest payment waiver Jun 19, 2024
@somasorosdpc somasorosdpc force-pushed the FINERACT-2092/new_transaction_type_payment-waiver branch from 45b0c6d to 952b085 Compare June 19, 2024 08:53
this.entityName = "LOAN";
this.entityId = null;
this.loanId = loanId;
this.href = "/loans/" + loanId + "/transactions/template?command=paymentwaiver";
Copy link
Contributor

Choose a reason for hiding this comment

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

Please change this to be "interestPaymentWaiver"

public CommandProcessingResult processCommand(final JsonCommand command) {
try {
return this.writePlatformService.makeInterestPaymentWaiver(command);
} catch (final JpaSystemException | DataIntegrityViolationException dve) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we can remove the try catch from here. Let it be handled in the error mappers ;)

}
}

public void validateLoanStatusIsActiveOrFullyPAidOrOverpaid(final Loan loan) {
Copy link
Contributor

Choose a reason for hiding this comment

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

typo in the method name

}

private boolean isForeclosure() {
public Integer getLoanSubStatus() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Lombok getter is on the Loan entity, so probably this getter method can be removed.

.addAdvancedPaymentAllocation(defaultAllocation, goodwillCreditAllocation, merchantIssuedRefundAllocation,
payoutRefundAllocation, interestPaymentWaiver)
.withInterestCalculationPeriodTypeAsRepaymentPeriod(true).withInterestTypeAsDecliningBalance().withMultiDisburse()
.withDisallowExpectedDisbursements(true).withLoanScheduleType(loanScheduleType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rewrite the test cases to the following:

  • Loans with interest
  • The test cases are checking the accounting entries are proper

@somasorosdpc somasorosdpc force-pushed the FINERACT-2092/new_transaction_type_payment-waiver branch 2 times, most recently from 7e3191a to 1316940 Compare June 20, 2024 14:14
@somasorosdpc somasorosdpc force-pushed the FINERACT-2092/new_transaction_type_payment-waiver branch from 1316940 to 580a8fb Compare June 20, 2024 14:26
this.entityName = "LOAN";
this.entityId = null;
this.loanId = loanId;
this.href = "/loans/" + loanId + "/transactions/template?command=interestpaymentwaiver";
Copy link
Contributor

Choose a reason for hiding this comment

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

typo: interestpaymentwaiver -> interestPaymentWaiver

Copy link
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 9152408 into apache:develop Jun 21, 2024
@somasorosdpc somasorosdpc deleted the FINERACT-2092/new_transaction_type_payment-waiver branch July 17, 2024 15:43
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