Fixes issue 21579: Process failed during execution when you post a GL Journal.
authorIoritz Cia <ioritz.cia@openbravo.com>
Tue, 11 Sep 2012 10:09:39 +0200
changeset 17942 05beb7bb79c2
parent 17941 163c8afae1d7
child 17943 8911868deda6
Fixes issue 21579: Process failed during execution when you post a GL Journal.
src/org/openbravo/erpCommon/ad_forms/Fact.java
--- a/src/org/openbravo/erpCommon/ad_forms/Fact.java	Thu Sep 13 15:54:51 2012 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/Fact.java	Tue Sep 11 10:09:39 2012 +0200
@@ -190,8 +190,24 @@
       return null;
     }
     if (strNegate.equals("N") && (DebitAmt.compareTo(ZERO) < 0 || CreditAmt.compareTo(ZERO) < 0)) {
-      return createLine(docLine, account, C_Currency_ID, CreditAmt.abs().toString(), DebitAmt.abs()
-          .toString(), Fact_Acct_Group_ID, SeqNo, DocBaseType, conn);
+      if (DebitAmt.compareTo(ZERO) < 0) {
+        CreditAmt = CreditAmt.add(DebitAmt.abs());
+        DebitAmt = BigDecimal.ZERO;
+      }
+      if (CreditAmt.compareTo(ZERO) < 0) {
+        DebitAmt = DebitAmt.add(CreditAmt.abs());
+        CreditAmt = BigDecimal.ZERO;
+      }
+      // If this is a manual entry then we need to recompute Amounts which were set in loadLines for
+      // GL Journal Document
+      if ("GLJ".equals(DocBaseType)) {
+        docLine.setConvertedAmt(docLine.m_C_AcctSchema_ID, DebitAmt.toString(),
+            CreditAmt.toString());
+      }
+      if (strNegate.equals("N") && (DebitAmt.compareTo(ZERO) < 0 || CreditAmt.compareTo(ZERO) < 0)) {
+        return createLine(docLine, account, C_Currency_ID, CreditAmt.abs().toString(), DebitAmt
+            .abs().toString(), Fact_Acct_Group_ID, SeqNo, DocBaseType, conn);
+      }
     }
 
     log4jFact.debug("createLine - " + account + " - Dr=" + debitAmt + ", Cr=" + creditAmt);