Fixes issue 29674: Error posting a payment if no access to Currency window
authorAtul Gaware <atul.gaware@openbravo.com>
Tue, 28 Jul 2015 20:07:53 +0530
changeset 30452 789db27692a6
parent 30451 ab62853b9b6c
child 30453 543c8285c581
Fixes issue 29674: Error posting a payment if no access to Currency window

Change OBContext to admin mode needed before accessing currency objects in isconvertible method of AcctServer class.
src/org/openbravo/erpCommon/ad_forms/AcctServer.java
--- a/src/org/openbravo/erpCommon/ad_forms/AcctServer.java	Mon Oct 10 17:12:47 2016 +0200
+++ b/src/org/openbravo/erpCommon/ad_forms/AcctServer.java	Tue Jul 28 20:07:53 2015 +0530
@@ -1275,19 +1275,24 @@
         if (conversionQuery != null) {
           conversionCount = conversionQuery.count();
         }
-        if (conversionCount > 0) {
-          List<ConversionRateDoc> conversionRate = conversionQuery.list();
-          OBCriteria<Currency> currencyCrit = OBDal.getInstance().createCriteria(Currency.class);
-          currencyCrit.add(Restrictions.eq(Currency.PROPERTY_ID, acctSchema.m_C_Currency_ID));
-          currencyCrit.setProjection(Projections.max(Currency.PROPERTY_STANDARDPRECISION));
-          Long precision = 0L;
-          if (currencyCrit.count() > 0) {
-            List<Currency> toCurrency = currencyCrit.list();
-            precision = toCurrency.get(0).getStandardPrecision();
+        try {
+          OBContext.setAdminMode(true);
+          if (conversionCount > 0) {
+            List<ConversionRateDoc> conversionRate = conversionQuery.list();
+            OBCriteria<Currency> currencyCrit = OBDal.getInstance().createCriteria(Currency.class);
+            currencyCrit.add(Restrictions.eq(Currency.PROPERTY_ID, acctSchema.m_C_Currency_ID));
+            currencyCrit.setProjection(Projections.max(Currency.PROPERTY_STANDARDPRECISION));
+            Long precision = 0L;
+            if (currencyCrit.count() > 0) {
+              List<Currency> toCurrency = currencyCrit.list();
+              precision = toCurrency.get(0).getStandardPrecision();
+            }
+            BigDecimal convertedAmount = new BigDecimal("1").multiply(conversionRate.get(0)
+                .getRate());
+            amt = convertedAmount.setScale(precision.intValue(), RoundingMode.HALF_UP).toString();
           }
-          BigDecimal convertedAmount = new BigDecimal("1")
-              .multiply(conversionRate.get(0).getRate());
-          amt = convertedAmount.setScale(precision.intValue(), RoundingMode.HALF_UP).toString();
+        } finally {
+          OBContext.restorePreviousMode();
         }
         if (("").equals(amt) || amt == null)
           amt = getConvertedAmt("1", currency, acctSchema.m_C_Currency_ID, DateAcct,