Fixes Issue 30273:"Not Balance" error received when posting a transaction
authorAtul Gaware <atul.gaware@openbravo.com>
Thu, 02 Jul 2015 22:07:27 +0530
changeset 27084 2cb16178b888
parent 27083 22f85795e81f
child 27085 adc2491ee60b
Fixes Issue 30273:"Not Balance" error received when posting a transaction
(although suspense balancing is not needed)

Fix takes into account the payment's sign (payment in/out).
src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Mon Jul 06 11:20:55 2015 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/DocFINFinAccTransaction.java	Thu Jul 02 22:07:27 2015 +0530
@@ -798,7 +798,7 @@
     if (payment != null) {
       if (!payment.getAccount().getCurrency().getId()
           .equalsIgnoreCase(payment.getCurrency().getId())) {
-        retValue = payment.getAmount();
+        retValue = payment.isReceipt() ? payment.getAmount() : payment.getAmount().negate();
       }
     }
     if (payment != null) {
@@ -817,7 +817,7 @@
               ((DocLine_FINFinAccTransaction) p_lines[i]).DepositAmount);
           lineBalance = lineBalance.subtract(new BigDecimal(
               ((DocLine_FINFinAccTransaction) p_lines[i]).PaymentAmount));
-          retValue = retValue.add(lineBalance);
+          retValue = retValue.subtract(lineBalance);
         } else {
           BigDecimal lineBalance = payment.isReceipt() ? new BigDecimal(
               ((DocLine_FINFinAccTransaction) p_lines[i]).getAmount()) : new BigDecimal(
@@ -825,7 +825,7 @@
           BigDecimal lineWriteoff = payment.isReceipt() ? new BigDecimal(
               ((DocLine_FINFinAccTransaction) p_lines[i]).getWriteOffAmt()) : new BigDecimal(
               ((DocLine_FINFinAccTransaction) p_lines[i]).getWriteOffAmt()).negate();
-          retValue = retValue.add(lineBalance).add(lineWriteoff);
+          retValue = retValue.subtract(lineBalance).subtract(lineWriteoff);
         }
       }
     } finally {