FINERACT-1806: Fix mapping to handle multiple loan product configuration
This commit is contained in:
+3
-2
@@ -66,8 +66,9 @@ public interface ProductToGLAccountMappingRepository
|
||||
List<ProductToGLAccountMapping> findAllChargeOffReasonsMappings(@Param("productId") Long productId,
|
||||
@Param("productType") int productType);
|
||||
|
||||
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.chargeOffReason.id =:chargeOffReasonId")
|
||||
ProductToGLAccountMapping findChargeOffReasonMappingById(@Param("chargeOffReasonId") Long chargeOffReasonId);
|
||||
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.chargeOffReason.id =:chargeOffReasonId AND mapping.productId =:productId AND mapping.productType =:productType")
|
||||
ProductToGLAccountMapping findChargeOffReasonMapping(@Param("productId") Long productId, @Param("productType") Integer productType,
|
||||
@Param("chargeOffReasonId") Long chargeOffReasonId);
|
||||
|
||||
@Query("select mapping from ProductToGLAccountMapping mapping where mapping.productId =:productId AND mapping.productType =:productType AND mapping.charge IS NULL AND mapping.paymentType IS NULL AND mapping.chargeOffReason IS NULL")
|
||||
List<ProductToGLAccountMapping> findAllRegularMappings(@Param("productId") Long productId, @Param("productType") Integer productType);
|
||||
|
||||
+3
-2
@@ -177,8 +177,9 @@ public class AccountingProcessorHelper {
|
||||
chargeOffReasonCodeValue);
|
||||
}
|
||||
|
||||
public ProductToGLAccountMapping getChargeOffMappingByCodeValue(Long chargeOffReasonCodeValue) {
|
||||
return accountMappingRepository.findChargeOffReasonMappingById(chargeOffReasonCodeValue);
|
||||
public ProductToGLAccountMapping getChargeOffMappingByCodeValue(Long loanProductId, PortfolioProductType productType,
|
||||
Long chargeOffReasonId) {
|
||||
return accountMappingRepository.findChargeOffReasonMapping(loanProductId, productType.getValue(), chargeOffReasonId);
|
||||
}
|
||||
|
||||
public SavingsDTO populateSavingsDtoFromMap(final Map<String, Object> accountingBridgeData, final boolean cashBasedAccountingEnabled,
|
||||
|
||||
+2
-1
@@ -37,6 +37,7 @@ import org.apache.fineract.accounting.journalentry.data.LoanTransactionDTO;
|
||||
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
|
||||
import org.apache.fineract.infrastructure.core.service.MathUtil;
|
||||
import org.apache.fineract.organisation.office.domain.Office;
|
||||
import org.apache.fineract.portfolio.PortfolioProductType;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -233,7 +234,7 @@ public class AccrualBasedAccountingProcessorForLoan implements AccountingProcess
|
||||
Long chargeOffReasonCodeValue = loanDTO.getChargeOffReasonCodeValue();
|
||||
|
||||
ProductToGLAccountMapping mapping = chargeOffReasonCodeValue != null
|
||||
? helper.getChargeOffMappingByCodeValue(chargeOffReasonCodeValue)
|
||||
? helper.getChargeOffMappingByCodeValue(loanProductId, PortfolioProductType.LOAN, chargeOffReasonCodeValue)
|
||||
: null;
|
||||
if (mapping != null) {
|
||||
GLAccount accountCredit = this.helper.getLinkedGLAccountForLoanProduct(loanProductId,
|
||||
|
||||
+7
-6
@@ -37,6 +37,7 @@ import org.apache.fineract.accounting.journalentry.service.AccountingProcessorHe
|
||||
import org.apache.fineract.accounting.journalentry.service.AccrualBasedAccountingProcessorForLoan;
|
||||
import org.apache.fineract.accounting.producttoaccountmapping.domain.ProductToGLAccountMapping;
|
||||
import org.apache.fineract.organisation.office.domain.Office;
|
||||
import org.apache.fineract.portfolio.PortfolioProductType;
|
||||
import org.apache.fineract.portfolio.loanaccount.data.LoanTransactionEnumData;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
@@ -48,7 +49,7 @@ import org.mockito.junit.jupiter.MockitoExtension;
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CreateJournalEntriesForChargeOffLoanTest {
|
||||
|
||||
private static final Long chargeOffReasons = 15L;
|
||||
private static final Long chargeOffReasonId = 15L;
|
||||
|
||||
@Mock
|
||||
private AccountingProcessorHelper helper;
|
||||
@@ -71,7 +72,7 @@ class CreateJournalEntriesForChargeOffLoanTest {
|
||||
transactionType, new BigDecimal("500.00"), new BigDecimal("500.00"), null, null, null, null, false, Collections.emptyList(),
|
||||
Collections.emptyList(), false, "", null, null, null, null);
|
||||
|
||||
loanDTO = new LoanDTO(1L, 1L, 1L, "USD", false, true, true, List.of(loanTransactionDTO), false, false, chargeOffReasons);
|
||||
loanDTO = new LoanDTO(1L, 1L, 1L, "USD", false, true, true, List.of(loanTransactionDTO), false, false, chargeOffReasonId);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -84,7 +85,7 @@ class CreateJournalEntriesForChargeOffLoanTest {
|
||||
ProductToGLAccountMapping chargeToGLAccountMapper = new ProductToGLAccountMapping();
|
||||
chargeToGLAccountMapper.setGlAccount(chargeOffGLAccount);
|
||||
|
||||
when(helper.getChargeOffMappingByCodeValue(chargeOffReasons)).thenReturn(chargeToGLAccountMapper);
|
||||
when(helper.getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId)).thenReturn(chargeToGLAccountMapper);
|
||||
|
||||
GLAccount loanPortfolioGLAccount = new GLAccount();
|
||||
loanPortfolioGLAccount.setId(20L);
|
||||
@@ -96,7 +97,7 @@ class CreateJournalEntriesForChargeOffLoanTest {
|
||||
|
||||
processor.createJournalEntriesForLoan(loanDTO);
|
||||
|
||||
verify(helper, times(1)).getChargeOffMappingByCodeValue(chargeOffReasons);
|
||||
verify(helper, times(1)).getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId);
|
||||
verify(helper, times(1)).getLinkedGLAccountForLoanProduct(1L, AccrualAccountsForLoan.LOAN_PORTFOLIO.getValue(), 1L);
|
||||
verify(helper, times(1)).createCreditJournalEntryOrReversalForLoan(helper.getOfficeById(1L), "USD",
|
||||
AccrualAccountsForLoan.LOAN_PORTFOLIO, 1L, null, 1L, "txn-123", LocalDate.now(ZoneId.systemDefault()),
|
||||
@@ -110,7 +111,7 @@ class CreateJournalEntriesForChargeOffLoanTest {
|
||||
void shouldCreateJournalEntriesForChargeOffWithFraud() {
|
||||
loanDTO.setMarkedAsFraud(true);
|
||||
|
||||
when(helper.getChargeOffMappingByCodeValue(chargeOffReasons)).thenReturn(null);
|
||||
when(helper.getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId)).thenReturn(null);
|
||||
|
||||
GLAccount loanPortfolioGLAccount = new GLAccount();
|
||||
loanPortfolioGLAccount.setId(20L);
|
||||
@@ -138,7 +139,7 @@ class CreateJournalEntriesForChargeOffLoanTest {
|
||||
void shouldCreateJournalEntriesForChargeOffWithoutFraud() {
|
||||
loanDTO.setMarkedAsFraud(false);
|
||||
|
||||
when(helper.getChargeOffMappingByCodeValue(chargeOffReasons)).thenReturn(null);
|
||||
when(helper.getChargeOffMappingByCodeValue(1L, PortfolioProductType.LOAN, chargeOffReasonId)).thenReturn(null);
|
||||
|
||||
GLAccount loanPortfolioGLAccount = new GLAccount();
|
||||
loanPortfolioGLAccount.setId(20L);
|
||||
|
||||
+510
-454
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user