- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2.1k
 
FINERACT-2324: Remove "loan.getLoanTransactions()" from reprocessing (reverse-replay) related actions #5041
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
base: develop
Are you sure you want to change the base?
Conversation
c014381    to
    9238eb9      
    Compare
  
            
          
                ...rc/main/java/org/apache/fineract/portfolio/loanaccount/domain/LoanTransactionRepository.java
          
            Show resolved
            Hide resolved
        
              
          
                ...loan/src/main/java/org/apache/fineract/portfolio/loanaccount/service/LoanBalanceService.java
          
            Show resolved
            Hide resolved
        
      | updateLoanSummaryDerivedFieldsInternal(loan, false); | ||
| } | ||
| 
               | 
          ||
| public void updateLoanSummaryDerivedFieldsViaPersistence(final Loan loan) { | 
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.
Same as above...
| } | ||
| 
               | 
          ||
| private void refreshSummaryAndBalancesForDisbursedLoanInternal(final Loan loan, final boolean viaPersistence) { | ||
| final Money overpaidBy = viaPersistence ? calculateTotalOverpaymentViaPersistence(loan) : calculateTotalOverpayment(loan); | 
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.
I dont think we should maintain two versions... use only 1 which fetches the required transactions.
| updateLoanOutstandingBalancesInternal(loan, loanTransactions); | ||
| } | ||
| 
               | 
          ||
| private void updateLoanOutstandingBalancesViaPersistence(final Loan loan) { | 
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.
Same as above
| && loanTransactionProcessingService.canProcessLatestTransactionOnly(loan, loanTransaction, currentInstallment); // | ||
| if (processLatest) { | ||
| loanTransactionProcessingService.processLatestTransaction(loan.getTransactionProcessingStrategyCode(), loanTransaction, | ||
| new TransactionCtx(loan.getCurrency(), loan.getRepaymentScheduleInstallments(), loan.getActiveCharges(), | 
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.
You might wanna rework the TransactionCtx a little bit and use Builder instead of constructor calls. With Builder pattern we can avoid set values to fields that are irrelevant to us: null and Collections.emptyList
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.
Done
| LocalDate currentDate = DateUtils.getBusinessLocalDate(); | ||
| Pair<ChangedTransactionDetail, ProgressiveLoanInterestScheduleModel> result = reprocessProgressiveLoanTransactions(disbursementDate, | ||
| currentDate, loanTransactions, currency, installments, charges); | ||
| currentDate, loanTransactionsToReprocess, currency, installments, charges, loanTransactions); | 
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.
what is the difference between loanTransactionsToReprocess and loanTransactions list?
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.
We have a reprocessParticularTransactions method, which in turn uses reprocessLoanTransactions, it passes certain specific transactions as the loanTransactionsToReprocess parameter. However, during reprocessing, we also need all loan transactions for certain calculations, so I introduced a new loanTransactions parameter that contains all loan transactions.
| if (savedModel.isPresent() && progressiveLoanModel.get().getBusinessDate().isBefore(businessDate)) { | ||
| ProgressiveTransactionCtx ctx = new ProgressiveTransactionCtx(loan.getCurrency(), loan.getRepaymentScheduleInstallments(), | ||
| Set.of(), new MoneyHolder(loan.getTotalOverpaidAsMoney()), new ChangedTransactionDetail(), savedModel.get()); | ||
| Set.of(), new MoneyHolder(loan.getTotalOverpaidAsMoney()), new ChangedTransactionDetail(), savedModel.get(), | 
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.
We can use Builder here and we dont need to create "dummy" objects.
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.
Done
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.
I dont see any changes.
| List<LoanTransaction> transactions = Collections.emptyList(); | ||
| if (loanTransaction.isInterestRefund() || loanTransaction.isContractTermination() || loanTransaction.isChargeback() | ||
| || loanTransaction.isChargeOff()) { | ||
| transactions = loan.getLoanTransactions(); | 
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.
why? we should stop using loan.getLoanTransactions() not introducing new occurrences... Please fetch from database the list of transactions that are required.
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.
Same here
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.
But you dont need the accrual transactions for example, right? So immediately you can fetch only the absolutely necessary transactions only. Am I missing something here?
| final ChangedTransactionDetail changedTransactionDetail = loanTransactionProcessingService.reprocessLoanTransactions( | ||
| loan.getTransactionProcessingStrategyCode(), loan.getDisbursementDate(), loanTransactions, loan.getCurrency(), | ||
| loan.getRepaymentScheduleInstallments(), loan.getActiveCharges()); | ||
| loan.getRepaymentScheduleInstallments(), loan.getActiveCharges(), loan.getLoanTransactions()); | 
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.
why? we should stop using loan.getLoanTransactions() not introducing new occurrences... Please fetch from database the list of transactions that are required.
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.
I tried to do so. But here is the same problem as above, connected to calling the loan.addLoanTransaction() method in services.
The challenge:
There are many places where we:
- First add new transaction to loan.loanTransactions
 - Call reprocessing methods
 - Only after that persist this new transaction
 
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.
Whenever we creates a new loan transactions, provide that or those transactions and as parameter can be added to the reprocessing.
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.
Please kindly see my review!
9238eb9    to
    d33e148      
    Compare
  
    | } else { | ||
| return loanRepaymentScheduleTransactionProcessor.reprocessLoanTransactions(disbursementDate, loanTransactions, currency, | ||
| installments, charges); | ||
| return loanRepaymentScheduleTransactionProcessor.reprocessLoanTransactions(disbursementDate, loanTransactionsToReprocess, | 
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.
what is the difference between loanTransactionsToReprocess and loanTransactions and why to provide both?
…(reverse-replay) related actions
d33e148    to
    fb91081      
    Compare
  
    …Transaction, builder for ProgressiveTransactionCtx
fb91081    to
    9fe158f      
    Compare
  
    …s()" from reprocessTransactionsAndFetchChangedTransactions
Description
Describe the changes made and why they were made.
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!
FYI our guidelines for code reviews are at https://cwiki.apache.org/confluence/display/FINERACT/Code+Review+Guide.