Fixes bug 28230 Null Pointer Exception is raised when trying to post a goods receipt
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Fri, 05 Dec 2014 08:51:10 +0100
changeset 25518 5da17f50c4b0
parent 25517 1a024cd666f7
child 25519 a8bd0fc47456
Fixes bug 28230 Null Pointer Exception is raised when trying to post a goods receipt

When a goods receipt with a product of type Service, which has a cost of type Standard, is posted, the DocInOut class calls the getStandardCost method from CostingUtils class with the currency of the current organization. If the organization has no currency, the client's currency will be used. Otherwise, a null pointer exception will be raised.
src/org/openbravo/erpCommon/ad_forms/DocInOut.java
src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java
--- a/src/org/openbravo/erpCommon/ad_forms/DocInOut.java	Tue Dec 09 10:03:20 2014 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocInOut.java	Fri Dec 05 08:51:10 2014 +0100
@@ -557,9 +557,11 @@
                   setMessageResult(conn, STATUS_InvalidCost, "error", parameters);
                   throw new IllegalStateException();
                 } else {
+                  Currency currency = legalEntity.getCurrency() != null ? legalEntity.getCurrency()
+                      : legalEntity.getClient().getCurrency();
                   trxCost = CostingUtils.getStandardCost(inOutLine.getProduct(), legalEntity,
-                      inOut.getAccountingDate(), costDimensions, legalEntity.getCurrency())
-                      .multiply(new BigDecimal(data[i].breakdownqty));
+                      inOut.getAccountingDate(), costDimensions, currency).multiply(
+                      new BigDecimal(data[i].breakdownqty));
                 }
               }
             }
--- a/src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java	Tue Dec 09 10:03:20 2014 +0100
+++ b/src/org/openbravo/erpCommon/ad_forms/DocMatchInv.java	Fri Dec 05 08:51:10 2014 +0100
@@ -66,8 +66,8 @@
     super(AD_Client_ID, AD_Org_ID, connectionProvider);
   }
 
-  public void loadObjectFieldProvider(ConnectionProvider conn,
-      @SuppressWarnings("hiding") String AD_Client_ID, String Id) throws ServletException {
+  public void loadObjectFieldProvider(ConnectionProvider conn, @SuppressWarnings("hiding")
+  String AD_Client_ID, String Id) throws ServletException {
     setObjectFieldProvider(DocMatchInvData.selectRegistro(conn, AD_Client_ID, Id));
   }
 
@@ -271,9 +271,11 @@
           throw new IllegalStateException();
 
         } else {
+          Currency currency = legalEntity.getCurrency() != null ? legalEntity.getCurrency()
+              : legalEntity.getClient().getCurrency();
           trxCost = CostingUtils.getStandardCost(inOutLine.getProduct(), legalEntity,
-              inOutLine.getShipmentReceipt().getAccountingDate(), costDimensions,
-              legalEntity.getCurrency()).multiply(new BigDecimal(data[0].getField("Qty")));
+              inOutLine.getShipmentReceipt().getAccountingDate(), costDimensions, currency)
+              .multiply(new BigDecimal(data[0].getField("Qty")));
         }
       } else {
         trxCost = transaction.getTransactionCost();
@@ -312,9 +314,11 @@
     String strIsSOTrx = invoiceData[0].issotrx;
     String strRecordId = invoiceData[0].cInvoiceId;
     String strReceiptDate = data[0].getField("ORDERDATEACCT");
-    BigDecimal bdExpenses = new BigDecimal(strExpenses).multiply(new BigDecimal(data[0].getField("QTY"))).divide(new BigDecimal(data[0].getField("QTYINVOICED")));
-    if ((new BigDecimal(data[0].getField("QTYINVOICED")).signum() != (new BigDecimal(data[0]
-        .getField("MOVEMENTQTY"))).signum())
+    BigDecimal bdExpenses = new BigDecimal(strExpenses).multiply(
+        new BigDecimal(data[0].getField("QTY"))).divide(
+        new BigDecimal(data[0].getField("QTYINVOICED")));
+    if ((new BigDecimal(data[0].getField("QTYINVOICED")).signum() != (new BigDecimal(
+        data[0].getField("MOVEMENTQTY"))).signum())
         && data[0].getField("InOutStatus").equals("VO")) {
       bdExpenses = bdExpenses.multiply(new BigDecimal(-1));
     }