svn commit: r955568 - /ofbiz/trunk/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: r955568 - /ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java

jleroux@apache.org
Author: jleroux
Date: Thu Jun 17 12:26:16 2010
New Revision: 955568

URL: http://svn.apache.org/viewvc?rev=955568&view=rev
Log:
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/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java

Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java?rev=955568&r1=955567&r2=955568&view=diff
==============================================================================
--- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java (original)
+++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/otherops/Calculate.java Thu Jun 17 12:26:16 2010
@@ -22,10 +22,12 @@ import java.math.BigDecimal;
 import java.text.DecimalFormat;
 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;
@@ -243,10 +245,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);