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


##########
fineract-accounting/src/main/java/org/apache/fineract/accounting/producttoaccountmapping/service/ProductToGLAccountMappingHelper.java:
##########
@@ -514,6 +594,26 @@ private void saveChargeOffReasonToExpenseMapping(final 
Long productId, final Lon
         }
     }
 
+    private void saveWriteOffReasonToExpenseMapping(final Long productId, 
final Long reasonId, final Long expenseAccountId,
+            final PortfolioProductType portfolioProductType) {
+
+        final Optional<GLAccount> glAccount = 
accountRepository.findById(expenseAccountId);
+
+        final boolean reasonMappingExists = this.accountMappingRepository
+                .findAllWriteOffReasonsMappings(productId, 
portfolioProductType.getValue()).stream()
+                .anyMatch(mapping -> 
mapping.getWriteOffReason().getId().equals(reasonId));
+
+        final Optional<CodeValue> codeValueOptional = 
codeValueRepository.findById(reasonId);
+
+        if (glAccount.isPresent() && !reasonMappingExists && 
codeValueOptional.isPresent()) {
+            final ProductToGLAccountMapping accountMapping = new 
ProductToGLAccountMapping().setGlAccount(glAccount.get())
+                    
.setProductId(productId).setFinancialAccountType(CashAccountsForLoan.LOSSES_WRITTEN_OFF.getValue())
+                    
.setProductType(portfolioProductType.getValue()).setWriteOffReason(codeValueOptional.get());
+
+            this.accountMappingRepository.saveAndFlush(accountMapping);
+        }
+    }
+

Review Comment:
   Same as above, please take a look whether the common parts can be extracted.



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