Cocoa-Puffs commented on code in PR #6067:
URL: https://github.com/apache/fineract/pull/6067#discussion_r3506302726


##########
integration-tests/src/test/java/org/apache/fineract/integrationtests/LoanBuyDownFeeTest.java:
##########
@@ -1029,4 +1032,68 @@ public void 
testBuyDownFeeWithAdvanceAccountingMappings() {
                     credit(feeIncomeAccount, 0.14)); // Second BuyDown Fee 
Without classification
         });
     }
+
+    @Test
+    public void 
testBuyDownFeePartialAdjustmentAfterFullAmortizationViaInvestorSale() {
+        final AtomicReference<Long> loanIdRef = new AtomicReference<>();
+        final AtomicReference<Long> buyDownFeeTransactionIdRef = new 
AtomicReference<>();
+
+        final Account transferAccount = 
accountHelper.createAssetAccount("transferInSuspense");
+        final FinancialActivityAccountHelper financialActivityAccountHelper = 
new FinancialActivityAccountHelper(requestSpec);
+        final ExternalAssetOwnerHelper externalAssetOwnerHelper = new 
ExternalAssetOwnerHelper();
+        
externalAssetOwnerHelper.setProperFinancialActivity(financialActivityAccountHelper,
 transferAccount);
+
+        final PostClientsResponse client = 
clientHelper.createClient(ClientHelper.defaultClientCreationRequest());
+        final PostLoanProductsResponse loanProduct = 
loanProductHelper.createLoanProduct(createProgressiveLoanProductWithBuyDownFee(null));
+
+        // Step 1: Create and disburse loan on July 1, 2026, add buydown fee, 
sell to investor
+        runAt("01 July 2026", () -> {
+            final Long loanId = 
applyAndApproveProgressiveLoan(client.getClientId(), 
loanProduct.getResourceId(), "01 July 2026", 1000.0,
+                    10.0, 6, null);
+            loanIdRef.set(loanId);
+            disburseLoan(loanId, BigDecimal.valueOf(1000.0), "01 July 2026");
+
+            final PostLoansLoanIdTransactionsResponse buyDownFeeResponse = 
loanTransactionHelper.makeLoanBuyDownFee(loanId, "01 July 2026",
+                    50.0);
+            buyDownFeeTransactionIdRef.set(buyDownFeeResponse.getResourceId());
+
+            externalAssetOwnerHelper.initiateTransferByLoanId(loanId, "sale",
+                    new 
ExternalAssetOwnerRequest().settlementDate("2026-07-01").dateFormat("yyyy-MM-dd").locale("en")
+                            
.transferExternalId(UUID.randomUUID().toString()).ownerExternalId(UUID.randomUUID().toString())
+                            .purchasePriceRatio("1.0"));
+        });
+
+        // Step 2: COB on July 2 — investor sale is processed → buydown fee 
should be fully amortized
+        runAt("02 July 2026", () -> {
+            final Long loanId = loanIdRef.get();
+            executeInlineCOB(loanId);
+
+            final GetLoansLoanIdResponse loanDetails = 
loanTransactionHelper.getLoanDetails(loanId);
+            assertNotNull(loanDetails.getTransactions());
+
+            final BigDecimal totalAmortized = 
loanDetails.getTransactions().stream()
+                    .filter(t -> t.getType() != null && 
Boolean.TRUE.equals(t.getType().getBuyDownFeeAmortization()))
+                    
.map(GetLoansLoanIdTransactions::getAmount).reduce(BigDecimal.ZERO, 
BigDecimal::add);
+            assertEquals(0, BigDecimal.valueOf(50.0).compareTo(totalAmortized),
+                    "Buydown fee should be fully amortized after investor 
sale");
+
+            loanTransactionHelper.buyDownFeeAdjustment(loanId, 
buyDownFeeTransactionIdRef.get(), "02 July 2026", 20.0);
+        });
+
+        // Step 4: COB on July 3 — expect amortization adjustment equal to the 
$20 partial adjustment
+        runAt("03 July 2026", () -> {
+            final Long loanId = loanIdRef.get();
+            executeInlineCOB(loanId);
+
+            final GetLoansLoanIdResponse loanDetails = 
loanTransactionHelper.getLoanDetails(loanId);
+            assertNotNull(loanDetails.getTransactions());
+
+            final Optional<GetLoansLoanIdTransactions> amortizationAdjustment 
= loanDetails.getTransactions().stream()
+                    .filter(t -> t.getType() != null && 
Boolean.TRUE.equals(t.getType().getBuyDownFeeAmortizationAdjustment())).findFirst();
+
+            assertTrue(amortizationAdjustment.isPresent());
+            assertEquals(0, 
BigDecimal.valueOf(20.0).compareTo(amortizationAdjustment.get().getAmount()),
+                    "Buy Down Fee Amortization Adjustment should match the $20 
partial adjustment");
+        });

Review Comment:
   yes, that was the case. I have modified the test to include a july 4th COB 
run to confirm that no new amortization adjustments are created on further runs



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to