-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FINERACT-1971: external_id column of accrual activity transaction gets updated to null when an accrual activity is reversed #4246
Open
kulminsky
wants to merge
1
commit into
apache:develop
Choose a base branch
from
kulminsky:FINERACT-1971/external_id_column_of_accrual_activity_transaction_gets_updated_to_null_when_an_accrual_activity_is_reversed
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -780,7 +780,6 @@ private static LoanTransaction useOldTransactionIfApplicable(LoanTransaction old | |
|
||
protected void createNewTransaction(final LoanTransaction oldTransaction, final LoanTransaction newTransaction, | ||
final TransactionCtx ctx) { | ||
oldTransaction.updateExternalId(null); | ||
oldTransaction.getLoanChargesPaid().clear(); | ||
|
||
if (newTransaction.getTypeOf().isInterestRefund()) { | ||
|
@@ -809,7 +808,11 @@ protected void createNewTransaction(final LoanTransaction oldTransaction, final | |
relations.add(LoanTransactionRelation.linkToTransaction(originalTransaction, newTransaction, CHARGEBACK)); | ||
} | ||
loanChargeValidator.validateRepaymentTypeTransactionNotBeforeAChargeRefund(oldTransaction.getLoan(), oldTransaction, "reversed"); | ||
oldTransaction.reverse(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. THis is not needed. The issue was not with this logic! |
||
boolean isReverseReplayed = oldTransaction.getLoanTransactionRelations().stream() | ||
.anyMatch(relation -> LoanTransactionRelationTypeEnum.REPLAYED.equals(relation.getRelationType())); | ||
|
||
oldTransaction.reverseWithExternalIdHandling(isReverseReplayed); | ||
} | ||
|
||
private void processSingleCharge(LoanCharge loanCharge, MonetaryCurrency currency, List<LoanRepaymentScheduleInstallment> installments, | ||
|
148 changes: 148 additions & 0 deletions
148
...ts/src/test/java/org/apache/fineract/integrationtests/RepaymentReverseExternalIdTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.fineract.integrationtests; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import io.restassured.builder.RequestSpecBuilder; | ||
import io.restassured.builder.ResponseSpecBuilder; | ||
import io.restassured.http.ContentType; | ||
import io.restassured.specification.RequestSpecification; | ||
import io.restassured.specification.ResponseSpecification; | ||
import java.math.BigDecimal; | ||
import java.time.LocalDate; | ||
import java.util.HashMap; | ||
import java.util.UUID; | ||
import org.apache.fineract.client.models.GetLoanProductsProductIdResponse; | ||
import org.apache.fineract.client.models.GetLoansLoanIdResponse; | ||
import org.apache.fineract.client.models.PostLoansLoanIdRequest; | ||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsRequest; | ||
import org.apache.fineract.client.models.PostLoansLoanIdTransactionsResponse; | ||
import org.apache.fineract.client.models.PutGlobalConfigurationsRequest; | ||
import org.apache.fineract.infrastructure.businessdate.domain.BusinessDateType; | ||
import org.apache.fineract.infrastructure.configuration.api.GlobalConfigurationConstants; | ||
import org.apache.fineract.integrationtests.common.BusinessDateHelper; | ||
import org.apache.fineract.integrationtests.common.ClientHelper; | ||
import org.apache.fineract.integrationtests.common.Utils; | ||
import org.apache.fineract.integrationtests.common.loans.LoanApplicationTestBuilder; | ||
import org.apache.fineract.integrationtests.common.loans.LoanProductTestBuilder; | ||
import org.apache.fineract.integrationtests.common.loans.LoanTransactionHelper; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class RepaymentReverseExternalIdTest extends BaseLoanIntegrationTest { | ||
|
||
private static final String loanAmount = "1000"; | ||
private static final String startDate = "20 December 2024"; | ||
private static final String firstRepaymentDate = "23 December 2024"; | ||
private static final String secondRepaymentDate = "26 December 2024"; | ||
private static final String reverseDate = "27 December 2024"; | ||
private static final Double firstRepaymentAmount = 1000.0; | ||
private static final Double secondRepaymentAmount = 10.0; | ||
|
||
private ResponseSpecification responseSpec; | ||
private RequestSpecification requestSpec; | ||
private ClientHelper clientHelper; | ||
private LoanTransactionHelper loanTransactionHelper; | ||
|
||
@BeforeEach | ||
public void setup() { | ||
Utils.initializeRESTAssured(); | ||
this.requestSpec = new RequestSpecBuilder().setContentType(ContentType.JSON).build(); | ||
this.requestSpec.header("Authorization", "Basic " + Utils.loginIntoServerAndGetBase64EncodedAuthenticationKey()); | ||
this.responseSpec = new ResponseSpecBuilder().expectStatusCode(200).build(); | ||
this.loanTransactionHelper = new LoanTransactionHelper(this.requestSpec, this.responseSpec); | ||
this.clientHelper = new ClientHelper(this.requestSpec, this.responseSpec); | ||
} | ||
|
||
@Test | ||
public void testReverseRepaymentUpdatesExternalIdCorrectlyForOverpayment() { | ||
try { | ||
// Set up the business date if required | ||
final LocalDate todaysDate = Utils.getLocalDateOfTenant(); | ||
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, | ||
new PutGlobalConfigurationsRequest().enabled(true)); | ||
BusinessDateHelper.updateBusinessDate(requestSpec, responseSpec, BusinessDateType.BUSINESS_DATE, todaysDate); | ||
|
||
// Create a client and a loan with externalId | ||
final Integer clientId = clientHelper.createClient(ClientHelper.defaultClientCreationRequest()).getClientId().intValue(); | ||
final GetLoanProductsProductIdResponse loanProduct = createLoanProduct(loanTransactionHelper, null); | ||
final String loanExternalId = UUID.randomUUID().toString(); | ||
final Integer loanId = createLoanAccount(clientId, loanProduct.getId(), loanExternalId); | ||
|
||
// First repayment to cover part of the loan | ||
final PostLoansLoanIdTransactionsResponse repaymentTransaction1 = loanTransactionHelper.makeLoanRepayment(loanExternalId, | ||
new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate(firstRepaymentDate).locale("en") | ||
.transactionAmount(firstRepaymentAmount)); | ||
|
||
// Second repayment to create overpayment | ||
final PostLoansLoanIdTransactionsResponse repaymentTransaction2 = loanTransactionHelper.makeLoanRepayment(loanExternalId, | ||
new PostLoansLoanIdTransactionsRequest().dateFormat("dd MMMM yyyy").transactionDate(secondRepaymentDate).locale("en") | ||
.transactionAmount(secondRepaymentAmount)); // This creates an overpayment as total is now | ||
// 1010 | ||
|
||
// Verify that the loan is marked as overpaid | ||
GetLoansLoanIdResponse loanDetailsOverpaid = loanTransactionHelper.getLoanDetails((long) loanId); | ||
assertTrue(loanDetailsOverpaid.getStatus().getOverpaid()); // Overpaid status should be true | ||
assertNotNull(loanDetailsOverpaid.getOverpaidOnDate()); // Overpaid date should be set | ||
assertEquals(loanDetailsOverpaid.getExternalId(), loanExternalId); // externalId should match the original | ||
|
||
// Reverse the second repayment to remove the overpayment | ||
loanTransactionHelper.reverseRepayment(loanId, repaymentTransaction2.getResourceId().intValue(), reverseDate); | ||
|
||
// Verify that the loan is no longer overpaid and overpaid date is reset | ||
GetLoansLoanIdResponse loanDetailsNotOverpaid = loanTransactionHelper.getLoanDetails((long) loanId); | ||
assertFalse(loanDetailsNotOverpaid.getStatus().getOverpaid()); // Overpaid status should be false | ||
assertNull(loanDetailsNotOverpaid.getOverpaidOnDate()); // Overpaid date should be reset | ||
assertEquals(loanDetailsNotOverpaid.getExternalId(), loanExternalId); // externalId should remain unchanged | ||
|
||
} finally { | ||
// Disable business date configuration if it was enabled | ||
globalConfigurationHelper.updateGlobalConfiguration(GlobalConfigurationConstants.ENABLE_BUSINESS_DATE, | ||
new PutGlobalConfigurationsRequest().enabled(false)); | ||
} | ||
} | ||
|
||
private GetLoanProductsProductIdResponse createLoanProduct(final LoanTransactionHelper loanTransactionHelper, | ||
final Integer delinquencyBucketId) { | ||
final HashMap<String, Object> loanProductMap = new LoanProductTestBuilder().build(null, delinquencyBucketId); | ||
final Integer loanProductId = loanTransactionHelper.getLoanProductId(Utils.convertToJson(loanProductMap)); | ||
return loanTransactionHelper.getLoanProduct(loanProductId); | ||
} | ||
|
||
private Integer createLoanAccount(final Integer clientID, final Long loanProductID, final String externalId) { | ||
|
||
String loanApplicationJSON = new LoanApplicationTestBuilder().withPrincipal(loanAmount).withLoanTermFrequency("1") | ||
.withLoanTermFrequencyAsMonths().withNumberOfRepayments("1").withRepaymentEveryAfter("1") | ||
.withRepaymentFrequencyTypeAsMonths().withInterestRatePerPeriod("0").withInterestTypeAsFlatBalance() | ||
.withAmortizationTypeAsEqualPrincipalPayments().withInterestCalculationPeriodTypeSameAsRepaymentPeriod() | ||
.withExpectedDisbursementDate(startDate).withSubmittedOnDate(startDate).withLoanType("individual") | ||
.withExternalId(externalId).build(clientID.toString(), loanProductID.toString(), null); | ||
|
||
final Integer loanId = loanTransactionHelper.getLoanId(loanApplicationJSON); | ||
loanTransactionHelper.approveLoan(startDate, loanAmount, loanId, null); | ||
loanTransactionHelper.disburseLoan(Long.valueOf(loanId), new PostLoansLoanIdRequest().actualDisbursementDate(startDate) | ||
.transactionAmount(new BigDecimal(loanAmount)).locale("en").dateFormat("dd MMMM yyyy")); | ||
return loanId; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not needed! I dont wanna move "reverse-replay" logic into the LoanTransaction entity...