details:   https://code.openbravo.com/erp/devel/pi/rev/89eaadd3beda
changeset: 29996:89eaadd3beda
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Wed Sep 07 09:23:12 2016 +0200
summary:   fixes issue 33900: Wrong decimal default value having ',' as decimal 
separator

When using a decimal value as default for a numeric column, this very same 
value is a String passed to the createFromClassicString of NumberUIDefinition 
which is used by the FIC to retrieve the column value. The default values are 
part of the code, so in case of decimal values, they must me defined as a valid 
Java decimal number. But the createFromClassicString expects a value formatted 
according to the Format.xml file.

For this reason, now the decimal default values are formatted properly. 
Although this value will be converted again in the createFromClassicString, 
this is the cleanest solution because for the rest of the flows within the FIC, 
the createFromClassicString method receives a value formatted according to the 
to the Format.xml file.

diffstat:

 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/NumberUIDefinition.java
 |  20 ++++++++
 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
       |  24 +++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)

diffs (85 lines):

diff -r 7ec80b84a711 -r 89eaadd3beda 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/NumberUIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/NumberUIDefinition.java
     Tue Sep 06 12:40:38 2016 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/NumberUIDefinition.java
     Wed Sep 07 09:23:12 2016 +0200
@@ -19,6 +19,7 @@
 package org.openbravo.client.kernel.reference;
 
 import java.math.BigDecimal;
+import java.text.DecimalFormat;
 
 import org.codehaus.jettison.json.JSONException;
 import org.codehaus.jettison.json.JSONObject;
@@ -27,6 +28,7 @@
 import org.openbravo.base.secureApp.VariablesSecureApp;
 import org.openbravo.client.kernel.RequestContext;
 import 
org.openbravo.client.kernel.reference.UIDefinitionController.FormatDefinition;
+import org.openbravo.erpCommon.utility.Utility;
 import org.openbravo.model.ad.ui.Field;
 
 /**
@@ -153,6 +155,24 @@
   }
 
   @Override
+  public String getDefaultValue(VariablesSecureApp vars, String columnName,
+      String defaultValueExpression, String windowId) {
+    String defaultValue = super.getDefaultValue(vars, columnName, 
defaultValueExpression, windowId);
+    if (defaultValue == null || defaultValue.length() == 0) {
+      return defaultValue;
+    }
+    try {
+      // Format the numeric default value
+      DecimalFormat df = Utility.getFormat(vars, getFormat());
+      BigDecimal numericDefaultValue = new BigDecimal(defaultValue);
+      return df.format(numericDefaultValue);
+    } catch (Exception ex) {
+      throw new OBException("Invalid numeric default value (" + 
defaultValueExpression
+          + ") defined for column " + columnName, ex);
+    }
+  }
+
+  @Override
   public Object createFromClassicString(String value) {
     if (value == null || value.length() == 0) {
       return null;
diff -r 7ec80b84a711 -r 89eaadd3beda 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
   Tue Sep 06 12:40:38 2016 +0000
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
   Wed Sep 07 09:23:12 2016 +0200
@@ -211,8 +211,7 @@
         if (defaultS.equalsIgnoreCase("@#Date@")) {
           return setNOWDefault();
         } else if (!defaultS.startsWith("@SQL=")) {
-          columnValue = Utility.getDefault(new DalConnectionProvider(false),
-              rq.getVariablesSecureApp(), colName, defaultS, windowId, "");
+          columnValue = getDefaultValue(rq.getVariablesSecureApp(), colName, 
defaultS, windowId);
         } else {
           ArrayList<String> params = new ArrayList<String>();
           String sql = parseSQL(defaultS, params);
@@ -269,6 +268,27 @@
   }
 
   /**
+   * Returns the value for a default value expression which represents a 
session value or a fixed
+   * value. This method is not used to calculate SQL based expressions (those 
that start with
+   * '@SQL=') and NOW expression ('@#Date@').
+   *
+   * @param vars
+   *          Handler for the session info.
+   * @param columnName
+   *          String with the name of the column that has the default value.
+   * @param defaultValueExpression
+   *          String with the default value expression.
+   * @param window
+   *          String with the window id.
+   * @return String with the calculated default value.
+   */
+  public String getDefaultValue(VariablesSecureApp vars, String columnName,
+      String defaultValueExpression, String windowId) {
+    return Utility.getDefault(new DalConnectionProvider(false), vars, 
columnName,
+        defaultValueExpression, windowId, "");
+  }
+
+  /**
    * It returns the same as getFieldProperties except in the case of combo 
UIDefinitions. In combo
    * UI definitions, a call to the super will be done, but the combo 
computation itself will not be
    * done (so only the default value, or the current request value, will be 
considered).

------------------------------------------------------------------------------
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to