Fixes issue 26379 Now No Conversion Rate error message is properly handled in Accounting Server
authorRafa Roda Palacios <rafa.roda@ubiquads.com>
Thu, 14 Aug 2014 14:21:48 +0200
changeset 24262 f98f86a4cf60
parent 24261 a5a296d4988d
child 24263 5ca94c9c9989
Fixes issue 26379 Now No Conversion Rate error message is properly handled in Accounting Server
src/org/openbravo/erpCommon/ad_forms/AcctServer.java
--- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java	Thu Aug 14 22:23:15 2014 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java	Thu Aug 14 14:21:48 2014 +0200
@@ -39,6 +39,7 @@
 import org.hibernate.criterion.Projections;
 import org.hibernate.criterion.Restrictions;
 import org.openbravo.advpaymentmngt.APRM_FinaccTransactionV;
+import org.openbravo.base.exception.OBException;
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.base.session.OBPropertiesProvider;
 import org.openbravo.client.kernel.RequestContext;
@@ -52,6 +53,7 @@
 import org.openbravo.erpCommon.utility.DateTimeData;
 import org.openbravo.erpCommon.utility.OBDateUtils;
 import org.openbravo.erpCommon.utility.OBError;
+import org.openbravo.erpCommon.utility.OBMessageUtils;
 import org.openbravo.erpCommon.utility.SequenceIdData;
 import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.exception.NoConnectionAvailableException;
@@ -1086,9 +1088,21 @@
     // createFacts
     try {
       m_fact[index] = createFact(m_as[index], conn, con, vars);
+    } catch (OBException e) {
+      log4j.warn(
+          "Accounting process failed. RecordID: " + Record_ID + " - TableId: " + AD_Table_ID, e);
+      String strMessageError = e.getMessage();
+      if (strMessageError.indexOf("") != -1) {
+        setMessageResult(OBMessageUtils.translateError(strMessageError));
+        if ("@NotConvertible@".equals(strMessageError)) {
+          return STATUS_NotConvertible;
+        }
+      }
+      return STATUS_Error;
     } catch (Exception e) {
       log4j.warn(
           "Accounting process failed. RecordID: " + Record_ID + " - TableId: " + AD_Table_ID, e);
+      return STATUS_Error;
     }
     if (!Status.equals(STATUS_NotPosted))
       return Status;
@@ -2393,8 +2407,13 @@
       if (conversionRateDoc != null) {
         amtFrom = applyRate(_amount, conversionRateDoc, false);
       } else {
-        amtFrom = new BigDecimal(getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo,
-            conversionDate, "", AD_Client_ID, AD_Org_ID, conn));
+        String convertedAmt = getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo,
+            conversionDate, "", AD_Client_ID, AD_Org_ID, conn);
+        if (convertedAmt != null && !"".equals(convertedAmt)) {
+          amtFrom = new BigDecimal(convertedAmt);
+        } else {
+          throw new OBException("@NotConvertible@");
+        }
       }
     }
     ConversionRateDoc conversionRateCurrentDoc = getConversionRateDoc(AD_Table_ID, Record_ID,
@@ -2439,8 +2458,13 @@
         amtTo = applyRate(_amount, conversionRateCurrentDoc, false);
         amtFromSourcecurrency = applyRate(amtFrom, conversionRateCurrentDoc, true);
       } else {
-        amtTo = new BigDecimal(getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo,
-            conversionDate, "", AD_Client_ID, AD_Org_ID, conn));
+        String convertedAmt = getConvertedAmt(_amount.toString(), currencyIDFrom, currencyIDTo,
+            conversionDate, "", AD_Client_ID, AD_Org_ID, conn);
+        if (convertedAmt != null && !"".equals(convertedAmt)) {
+          amtTo = new BigDecimal(convertedAmt);
+        } else {
+          throw new OBException("@NotConvertible@");
+        }
         amtFromSourcecurrency = amtFrom.multiply(_amount).divide(amtTo, conversionRatePrecision,
             BigDecimal.ROUND_HALF_EVEN);
       }