Fixes bug 32613:Not possible to execute Automatic Deposit payment created in FA
authorAtul Gaware <atul.gaware@openbravo.com>
Wed, 06 Apr 2016 15:23:01 +0530
changeset 29580 3236f229b7ae
parent 28970 21c8ed48293c
child 29581 cd0e228f5af4
Fixes bug 32613:Not possible to execute Automatic Deposit payment created in FA

Before creating a record in financial account transaction, check is done: if transaction exists, get it so that no transactiom is created and the same is sent for processing
modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java
--- a/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java	Thu Mar 17 05:54:24 2016 +0000
+++ b/modules/org.openbravo.advpaymentmngt/src/org/openbravo/advpaymentmngt/process/FIN_ExecutePayment.java	Wed Apr 06 15:23:01 2016 +0530
@@ -25,6 +25,7 @@
 import java.util.Set;
 
 import org.apache.commons.lang.StringUtils;
+import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.dao.AdvPaymentMngtDao;
 import org.openbravo.advpaymentmngt.dao.TransactionsDao;
 import org.openbravo.advpaymentmngt.exception.NoExecutionProcessFoundException;
@@ -34,6 +35,7 @@
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.client.kernel.RequestContext;
 import org.openbravo.dal.core.OBContext;
+import org.openbravo.dal.service.OBCriteria;
 import org.openbravo.dal.service.OBDal;
 import org.openbravo.database.ConnectionProvider;
 import org.openbravo.erpCommon.utility.OBError;
@@ -194,8 +196,17 @@
                     if (FIN_Utility.isAutomaticDepositWithdrawn(paymentRunPayment.getPayment())
                         && paymentRunPayment.getPayment().getAmount().compareTo(BigDecimal.ZERO) != 0
                         && !StringUtils.equals(internalParameters.get("comingFrom"), "TRANSACTION")) {
-                      FIN_FinaccTransaction transaction = TransactionsDao
-                          .createFinAccTransaction(paymentRunPayment.getPayment());
+                      OBCriteria<FIN_FinaccTransaction> finAccTransactionCriteria = OBDal
+                          .getInstance().createCriteria(FIN_FinaccTransaction.class);
+                      finAccTransactionCriteria.add(Restrictions.eq(
+                          FIN_FinaccTransaction.PROPERTY_FINPAYMENT, payment));
+                      finAccTransactionCriteria.setMaxResults(1);
+                      FIN_FinaccTransaction transaction = (FIN_FinaccTransaction) finAccTransactionCriteria
+                          .uniqueResult();
+                      if (transaction == null) {
+                        transaction = TransactionsDao.createFinAccTransaction(paymentRunPayment
+                            .getPayment());
+                      }
                       VariablesSecureApp vars = new VariablesSecureApp(RequestContext.get()
                           .getRequest());
                       OBError processTransactionError = processTransaction(vars,