Fixes issue 29029: SL_Journal_Period raises a NullPointer Exception
authorAlvaro Ferraz <alvaro.ferraz@openbravo.com>
Mon, 23 Feb 2015 18:52:28 +0100
changeset 26078 e72f5b99ab8b
parent 26077 46a20957f70c
child 26079 83ddad268c60
Fixes issue 29029: SL_Journal_Period raises a NullPointer Exception

AcctSchema will be retrieved only if acctSchemaId is not null (G/L Journal Header tab). In other case (G/L Journal Batch tab) it will not.
src/org/openbravo/erpCommon/ad_callouts/SL_Journal_Period.java
--- a/src/org/openbravo/erpCommon/ad_callouts/SL_Journal_Period.java	Tue Feb 24 14:12:20 2015 +0100
+++ b/src/org/openbravo/erpCommon/ad_callouts/SL_Journal_Period.java	Mon Feb 23 18:52:28 2015 +0100
@@ -79,16 +79,18 @@
     String stradClientId = vars.getClient();
     final String stradOrgId = vars.getGlobalVariable("inpadOrgId", "SL_Journal_Period|adOrgId", "");
 
-    AcctSchema acctSchema = OBDal.getInstance().get(AcctSchema.class, strAcctSchemaId);
+    OBError myMessage = null;
     String currencyRate = null;
-    OBError myMessage = null;
-    try {
-      currencyRate = SLJournalPeriodData.getCurrencyRate(this, strCurrencyId, acctSchema
-          .getCurrency().getId(), strDateAcctNew, strCurrencyRateType, stradClientId, stradOrgId,
-          strAcctSchemaId);
-    } catch (Exception e) {
-      myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
-      log4j.warn("Currency does not exist. Exception:" + e);
+    if (strAcctSchemaId != null && !strAcctSchemaId.isEmpty()) {
+      AcctSchema acctSchema = OBDal.getInstance().get(AcctSchema.class, strAcctSchemaId);
+      try {
+        currencyRate = SLJournalPeriodData.getCurrencyRate(this, strCurrencyId, acctSchema
+            .getCurrency().getId(), strDateAcctNew, strCurrencyRateType, stradClientId, stradOrgId,
+            strAcctSchemaId);
+      } catch (Exception e) {
+        myMessage = Utility.translateError(this, vars, vars.getLanguage(), e.getMessage());
+        log4j.warn("Currency does not exist. Exception:" + e);
+      }
     }
 
     String strDateAcct = strDateAcctNew;
@@ -132,6 +134,8 @@
     resultado.append("new Array(\"inpcPeriodId\", \"" + strcPeriodId + "\"),");
     if (myMessage != null) {
       resultado.append("new Array('MESSAGE', \"" + myMessage.getMessage() + "\"),");
+    }
+    if (currencyRate == null) {
       resultado.append("new Array(\"inpcurrencyrate\", \"" + "1" + "\")");
     } else {
       resultado.append("new Array(\"inpcurrencyrate\", \"" + currencyRate.toString() + "\")");