adamsaghy commented on code in PR #4634:
URL: https://github.com/apache/fineract/pull/4634#discussion_r2081230665


##########
fineract-progressive-loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/InterestScheduleModelRepositoryWrapperImpl.java:
##########
@@ -87,22 +87,40 @@ public Optional<ProgressiveLoanInterestScheduleModel> 
extractModel(Optional<Prog
                         
progressiveLoanModel.get().getLoan().getLoanProduct().getInstallmentAmountInMultiplesOf()));
     }
 
+    @Override
+    public boolean hasValidModelForDate(Long loanId, LocalDate targetDate) {
+        try {
+            entityManager.setFlushMode(FlushModeType.COMMIT);
+            Optional<ProgressiveLoanModel> progressiveLoanModel = 
findOneByLoanId(loanId);
+            LocalDate modelUpdatedTilDate = 
progressiveLoanModel.map(ProgressiveLoanModel::getBusinessDate).orElse(null);
+            return progressiveLoanModel.isPresent() && 
!targetDate.isBefore(modelUpdatedTilDate);
+        } finally {
+            entityManager.setFlushMode(FlushModeType.AUTO);
+        }
+    }
+
     @Override
     public Optional<ProgressiveLoanInterestScheduleModel> getSavedModel(Loan 
loan, LocalDate businessDate) {
-        Optional<ProgressiveLoanModel> progressiveLoanModel = 
findOneByLoanId(loan.getId());
-        Optional<ProgressiveLoanInterestScheduleModel> savedModel;
-        if (progressiveLoanModel.isPresent() && 
!progressiveLoanModel.get().getBusinessDate().isAfter(businessDate)) {
-            savedModel = extractModel(progressiveLoanModel);
-            if 
(progressiveLoanModel.get().getBusinessDate().isBefore(businessDate) && 
savedModel.isPresent()) {
-                ProgressiveTransactionCtx ctx = new 
ProgressiveTransactionCtx(loan.getCurrency(), 
loan.getRepaymentScheduleInstallments(),
-                        Set.of(), new 
MoneyHolder(loan.getTotalOverpaidAsMoney()), new ChangedTransactionDetail(), 
savedModel.get());
-                ctx.setChargedOff(loan.isChargedOff());
-                
advancedPaymentScheduleTransactionProcessor.recalculateInterestForDate(businessDate,
 ctx);
+        try {
+            entityManager.setFlushMode(FlushModeType.COMMIT);

Review Comment:
   Please leave a comment why we change flush mode for future reference!



-- 
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