fixed bug 30993: can't define default with preference if column has default
authorAsier Lostalé <asier.lostale@openbravo.com>
Mon, 05 Oct 2015 09:57:41 +0200
changeset 27646 241c38dab7ce
parent 27645 29524c0b6c24
child 27647 f1f0e628b7d9
fixed bug 30993: can't define default with preference if column has default

When a column had a default value, it was not possible to overwrite it using a
preference. This was possible if the column had not default value.

This behavior has been changed: now default value defined at preference prevails
over the one defined at column level.
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	Thu Oct 01 14:31:43 2015 +0530
+++ b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java	Mon Oct 05 09:57:41 2015 +0200
@@ -183,7 +183,21 @@
                 field.getTab().getWindow().getId(), field.getColumn().getTable().getDBTableName(),
                 docTypeTarget, docType, false, false) + ">";
       } else {
-        String defaultS = field.getColumn().getDefaultValue();
+        final String windowId = field.getTab().getWindow().getId();
+        final String colName = field.getColumn().getDBColumnName();
+
+        final String prefValue = Utility.getPreference(rq.getVariablesSecureApp(), colName,
+            windowId);
+
+        String defaultS;
+        if (StringUtils.isNotBlank(prefValue)) {
+          // if there is a preference for this field, use it instead of the one that might be
+          // defined at column level
+          defaultS = prefValue;
+        } else {
+          defaultS = field.getColumn().getDefaultValue();
+        }
+
         if (defaultS == null || defaultS.equals("\"\"")) {
           defaultS = "";
         }
@@ -191,8 +205,7 @@
           return setNOWDefault();
         } else if (!defaultS.startsWith("@SQL=")) {
           columnValue = Utility.getDefault(new DalConnectionProvider(false),
-              rq.getVariablesSecureApp(), field.getColumn().getDBColumnName(), defaultS, field
-                  .getTab().getWindow().getId(), "");
+              rq.getVariablesSecureApp(), colName, defaultS, windowId, "");
         } else {
           ArrayList<String> params = new ArrayList<String>();
           String sql = parseSQL(defaultS, params);