details:   https://code.openbravo.com/erp/devel/pi/rev/b0c64f2ef32d
changeset: 33118:b0c64f2ef32d
user:      Javier Armendáriz <javier.armendariz <at> openbravo.com>
date:      Fri Dec 15 09:16:47 2017 +0100
summary:   Fixes bug 36897: Inconsistent date format for default value in 
String reference

Depending on which UIDefinition is picked up first, different Date 
UIDefinitions could be used to format the @#Date@ expression as the default 
value of a String field. Now we use DateTimeUIDefinition to ensure we always 
apply the same date format.

diffstat:

 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
 |  24 ++++-----
 1 files changed, 11 insertions(+), 13 deletions(-)

diffs (56 lines):

diff -r 93673c76d8cc -r b0c64f2ef32d 
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
   Mon Dec 04 14:33:36 2017 +0100
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/UIDefinition.java
   Fri Dec 15 09:16:47 2017 +0100
@@ -64,7 +64,8 @@
  */
 public abstract class UIDefinition {
   private static final String TYPE_NAME_PREFIX = "_id_";
-  private static final String LIST_REF_ID = "17";
+  private static final String LIST_REFERENCE_ID = "17";
+  private static final String DATETIME_REFERENCE_ID = "16";
 
   private Reference reference;
   private DomainType domainType;
@@ -333,25 +334,22 @@
   }
 
   private String setNOWDefault() {
-    JSONObject jsnobject = new JSONObject();
+    JSONObject jsonObject = new JSONObject();
     try {
       UIDefinition uiDef = this;
       if (!(this instanceof DateUIDefinition)) {
-        for (UIDefinition def : 
UIDefinitionController.getInstance().getAllUIDefinitions()) {
-          if (def instanceof DateUIDefinition) {
-            uiDef = def;
-            break;
-          }
-        }
+        Reference datetimeReference = 
OBDal.getInstance().getProxy(Reference.class,
+            DATETIME_REFERENCE_ID);
+        uiDef = 
UIDefinitionController.getInstance().getUIDefinition(datetimeReference);
       }
       String columnValue = uiDef.convertToClassicString(new Date());
-      jsnobject.put("value", uiDef.createFromClassicString(columnValue));
-      jsnobject.put("classicValue", columnValue);
-      jsnobject.put("hasDateDefault", true);
+      jsonObject.put("value", uiDef.createFromClassicString(columnValue));
+      jsonObject.put("classicValue", columnValue);
+      jsonObject.put("hasDateDefault", true);
     } catch (JSONException e) {
       log.error("Couldn't get field property value");
     }
-    return jsnobject.toString();
+    return jsonObject.toString();
   }
 
   /**
@@ -600,7 +598,7 @@
       String columnValue, boolean onlyFirstRecord) {
     try {
       String ref = field.getColumn().getReference().getId();
-      boolean isListReference = LIST_REF_ID.equals(ref);
+      boolean isListReference = LIST_REFERENCE_ID.equals(ref);
       if (!isListReference && !field.getColumn().isMandatory() && 
StringUtils.isEmpty(columnValue)) {
         // non mandatory without value nor default, should only return empty 
value, prevent
         // everything else

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to