Fixes issue 33688: Error when posting a financial account transaction
authorRafael Queralta Pozo <rqueralta@nauta.cu>
Tue, 16 Aug 2016 12:42:05 +0200
changeset 29863 0be06d363c58
parent 29862 f5025b20aee1
child 29864 e5ecc0ed32a1
Fixes issue 33688: Error when posting a financial account transaction

Avoid laizy initialization error by reloading transaction object from database after clearing the session.
Session clearing will not be done in first iteration but starting from iteration number 100. This doesn't solve clear session problem but will raise it only when we iterate at least 100 times.
src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java
src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Fri Aug 12 11:26:25 2016 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Tue Aug 16 12:42:05 2016 +0200
@@ -299,7 +299,7 @@
             paymentDetail.isPrepayment() ? (pso != null ? pso.getId() : "") : (psi != null ? psi
                 .getId() : ""));
 
-        if (i % 100 == 0) {
+        if ((i + 1) % 100 == 0) {
           OBDal.getInstance().getSession().clear();
         }
       }
@@ -633,12 +633,13 @@
           }
         }
 
-        if (i % 100 == 0) {
+        if ((i + 1) % 100 == 0) {
           OBDal.getInstance().getSession().clear();
         }
       }
       // Pre-payment is consumed when Used Credit Amount not equals Zero. When consuming Credit no
       // credit is generated
+      transaction = OBDal.getInstance().get(FIN_FinaccTransaction.class, Record_ID);
       if (transaction.getFinPayment().getUsedCredit().compareTo(ZERO) != 0
           && transaction.getFinPayment().getGeneratedCredit().compareTo(ZERO) == 0) {
         List<FIN_Payment_Credit> creditPayments = transaction.getFinPayment()
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java	Fri Aug 12 11:26:25 2016 +0000
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINPayment.java	Tue Aug 16 12:42:05 2016 +0200
@@ -262,7 +262,7 @@
             paymentDetail.isPrepayment() ? (pso != null ? pso.getId() : "") : (psi != null ? psi
                 .getId() : ""));
 
-        if (i % 100 == 0) {
+        if ((i + 1) % 100 == 0) {
           OBDal.getInstance().getSession().clear();
         }
       }
@@ -476,7 +476,7 @@
               (isReceipt ? bpAmount : ""), Fact_Acct_Group_ID, nextSeqNo(SeqNo), DocumentType, conn);
         }
 
-        if (i % 100 == 0) {
+        if ((i + 1) % 100 == 0) {
           OBDal.getInstance().getSession().clear();
         }
       }