Openbravo Issue Tracking System - Openbravo ERP
View Issue Details
0046309Openbravo ERP09. Financial managementpublic2021-04-20 16:452021-04-21 11:59
gsuarez 
Triage Omni OMS 
highmajoralways
closedno change required 
5
 
 
vmromanos
Advanced Payables and Receivables Mngmt
No
0046309: Error in getConversionRate function of FIN_Utility class that belongs to org.openbravo.advpaymentmngt module
In a custom process we use this function to get the conversion rate between 2 differents currencies. Openbravo only has records of conversion rate at organization 0 (*), but this function returns null when the organization is 0.
I copy the function:

public static ConversionRate getConversionRate(Currency fromCurrency, Currency toCurrency,
      Date conversionDate, Organization org) {
    java.util.List<ConversionRate> conversionRateList;
    ConversionRate conversionRate;
    OBContext.setAdminMode(true);
    try {
      final OBCriteria<ConversionRate> obcConvRate = OBDal.getInstance()
          .createCriteria(ConversionRate.class);
      obcConvRate.setFilterOnReadableOrganization(false);
      obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_ORGANIZATION, org));
      obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_CURRENCY, fromCurrency));
      obcConvRate.add(Restrictions.eq(ConversionRate.PROPERTY_TOCURRENCY, toCurrency));
      obcConvRate.add(Restrictions.le(ConversionRate.PROPERTY_VALIDFROMDATE, conversionDate));
      long oneDay = 24 * 60 * 60 * 1000;
      obcConvRate.add(Restrictions.ge(ConversionRate.PROPERTY_VALIDTODATE,
          new Date(conversionDate.getTime() - oneDay)));
      conversionRateList = obcConvRate.list();
      if ((conversionRateList != null) && (conversionRateList.size() != 0)) {
        conversionRate = conversionRateList.get(0);
      } else {
        if ("0".equals(org.getId())) {
          conversionRate = null;
        } else {
          return getConversionRate(fromCurrency, toCurrency, conversionDate,
              OBDal.getInstance()
                  .get(Organization.class,
                      OBContext.getOBContext()
                          .getOrganizationStructureProvider()
                          .getParentOrg(org.getId())));
        }
      }
    } catch (Exception e) {
      log4j.error("Error getting conversion rate", e);
      return null;
    } finally {
      OBContext.restorePreviousMode();
    }
    return conversionRate;
  }
In a custom process, try to get a conversion rate using this function.
No tags attached.
Issue History
2021-04-20 16:45gsuarezNew Issue
2021-04-20 16:45gsuarezAssigned To => Triage Finance
2021-04-20 16:45gsuarezModules => Advanced Payables and Receivables Mngmt
2021-04-20 16:45gsuarezResolution time => 1620684000
2021-04-20 16:45gsuarezTriggers an Emergency Pack => No
2021-04-21 11:59vmromanosReview Assigned To => vmromanos
2021-04-21 11:59vmromanosNote Added: 0127412
2021-04-21 11:59vmromanosStatusnew => closed
2021-04-21 11:59vmromanosResolutionopen => no change required

Notes
(0127412)
vmromanos   
2021-04-21 11:59   
Although Openbravo only allows to define conversion rates at * level, the method is ready to support conversion rates defined in any other organization. Let's see what it does:

1. It searches for a conversion rate defined for the organization passed as parameter.
2. If it is found it is returned and the process ends, otherwise the process continues..
3. If it is not found it tries to search **recursively** through the parent tree till it finds a conversion rate and then returns it.
4. If it is not found and the organization is '0', it means that we have checked all the possibilities, so we return null.

To return null when organization is '0' is the exit point of this recursive method. We can't remove it. And besides that, it's not necessary to change anything in this method because it already supports what you're expecting.

Rejected as no change required.