svn commit: r956054 - /ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r956054 - /ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java

jleroux@apache.org
Author: jleroux
Date: Fri Jun 18 17:27:35 2010
New Revision: 956054

URL: http://svn.apache.org/viewvc?rev=956054&view=rev
Log:
"Applied fix from trunk for revision: 955568" (actually done by hand I thought it was already done but found that it was blocked by a tree conflict in googleCheckout
------------------------------------------------------------------------
r955568 | jleroux | 2010-06-17 14:26:16 +0200 (jeu. 17 juin 2010) | 16 lignes

A patch from Shubham Dubey "Using number value with calcop operator does not work as thought" (https://issues.apache.org/jira/browse/OFBIZ-3821) - OFBIZ-3821

For instance if you use

<calcop operator="multiply" field="parameters.numberSpecified">
    <number value="${uomConversion.conversionFactor}"/>

and have a value > 1000 in conversionFactor you will get 1,000 for number value. It works well if you replace by

<calcop operator="multiply">
    <calcop operator="get" field="parameters.numberSpecified"/>
    <calcop operator="get" field="uomConversion.conversionFactor"/>

The problem exists in trunk and certainly R10.04 (not tested) maybe in previous release though I don't think so, it looks like something introduced with UEL


------------------------------------------------------------------------


Modified:
    ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java

Modified: ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java?rev=956054&r1=956053&r2=956054&view=diff
==============================================================================
--- ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java (original)
+++ ofbiz/branches/release09.04/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java Fri Jun 18 17:27:35 2010
@@ -24,10 +24,12 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Locale;
 
 import javolution.util.FastMap;
 
 import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.ObjectType;
 import org.ofbiz.base.util.UtilValidate;
 import org.ofbiz.base.util.UtilXml;
 import org.ofbiz.minilang.SimpleMethod;
@@ -242,10 +244,14 @@ public class Calculate extends MethodOpe
 
         public BigDecimal calcValue(MethodContext methodContext, int scale, int roundingMode) {
             String valueStr = methodContext.expandString(this.valueStr);
+            Locale locale = (Locale) methodContext.getLocale();
+
+            if (locale == null) locale = Locale.getDefault();
+            
             BigDecimal value;
             try {
-                value = new BigDecimal(valueStr);
-                value = value.setScale(scale, roundingMode);
+                BigDecimal parseVal = (BigDecimal) ObjectType.simpleTypeConvert(valueStr, "BigDecimal", null, null, locale, true);
+                value = parseVal.setScale(scale, roundingMode);
             } catch (Exception e) {
                 Debug.logError(e, "Could not parse the number string: " + valueStr, module);
                 throw new IllegalArgumentException("Could not parse the number string: " + valueStr);