details:   https://code.openbravo.com/erp/devel/pi/rev/70609c699271
changeset: 25688:70609c699271
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Jan 09 07:44:53 2015 +0100
summary:   fixed bug 28541: date value in DateTime reference changes to current 
date

  When a DateTime reference column is hidden in grid, the date part was set to
  current date when navigating to form view.

  This was caused by an incorrect conversion to UTC where current date was set.

details:   https://code.openbravo.com/erp/devel/pi/rev/1d19422a82a2
changeset: 25689:1d19422a82a2
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Jan 09 07:45:56 2015 +0100
summary:   related to bug 28541: added test case

details:   https://code.openbravo.com/erp/devel/pi/rev/8d45fed594e7
changeset: 25690:8d45fed594e7
user:      Asier Lostalé <asier.lostale <at> openbravo.com>
date:      Fri Jan 09 07:48:24 2015 +0100
summary:   related to bug 28541: added FICTest.class to AllWebserviceTests suite

diffstat:

 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
 |  14 +-
 src-test/src/org/openbravo/test/AllWebserviceTests.java                        
                         |   8 +-
 src-test/src/org/openbravo/test/datasource/FICTest.java                        
                         |  48 +++++++++-
 3 files changed, 56 insertions(+), 14 deletions(-)

diffs (165 lines):

diff -r 437ac768ed53 -r 8d45fed594e7 
modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
--- 
a/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
   Fri Jan 09 11:54:38 2015 +0530
+++ 
b/modules/org.openbravo.client.kernel/src/org/openbravo/client/kernel/reference/DateTimeUIDefinition.java
   Fri Jan 09 07:48:24 2015 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -35,7 +35,6 @@
 public class DateTimeUIDefinition extends DateUIDefinition {
   private String lastUsedPattern = null;
   private SimpleDateFormat dateFormat = null;
-  private static final SimpleDateFormat ficDateFormat = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 
   @Override
   public String getParentType() {
@@ -65,17 +64,14 @@
     return convertedValue.toString();
   }
 
-  private StringBuffer convertLocalDateTimeToUTC(Date UTCDate) {
+  private StringBuffer convertLocalDateTimeToUTC(Date date) {
     StringBuffer localTimeColumnValue = null;
-    Calendar now = Calendar.getInstance();
 
     Calendar calendar = Calendar.getInstance();
-    calendar.setTime(UTCDate);
-    calendar.set(Calendar.DATE, now.get(Calendar.DATE));
-    calendar.set(Calendar.MONTH, now.get(Calendar.MONTH));
-    calendar.set(Calendar.YEAR, now.get(Calendar.YEAR));
+    calendar.setTime(date);
 
-    int gmtMillisecondOffset = (now.get(Calendar.ZONE_OFFSET) + 
now.get(Calendar.DST_OFFSET));
+    int gmtMillisecondOffset = (calendar.get(Calendar.ZONE_OFFSET) + calendar
+        .get(Calendar.DST_OFFSET));
     calendar.add(Calendar.MILLISECOND, -gmtMillisecondOffset);
     localTimeColumnValue = getClassicFormat().format(calendar.getTime(), new 
StringBuffer(),
         new FieldPosition(0));
diff -r 437ac768ed53 -r 8d45fed594e7 
src-test/src/org/openbravo/test/AllWebserviceTests.java
--- a/src-test/src/org/openbravo/test/AllWebserviceTests.java   Fri Jan 09 
11:54:38 2015 +0530
+++ b/src-test/src/org/openbravo/test/AllWebserviceTests.java   Fri Jan 09 
07:48:24 2015 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2010-2014 Openbravo SLU 
+ * All portions are Copyright (C) 2010-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -21,6 +21,7 @@
 
 import org.junit.runner.RunWith;
 import org.junit.runners.Suite;
+import org.openbravo.test.datasource.FICTest;
 import org.openbravo.test.datasource.FKDropDownDatasource;
 import org.openbravo.test.datasource.ProductSelectorDataSourceTest;
 import org.openbravo.test.datasource.SelectorFieldPropertySelectorDSTest;
@@ -33,7 +34,7 @@
 import org.openbravo.test.webservice.WSUpdateTest;
 
 /**
- * This test suite should only contain test cases which are to run the 
weservices included in core.
+ * This test suite should only contain test cases which are to run the 
webservices included in core.
  * 
  * 
  */
@@ -50,6 +51,7 @@
     ProductSelectorDataSourceTest.class, //
     TestComboDatasource.class, //
     FKDropDownDatasource.class, //
-    JSONWebServices.class })
+    JSONWebServices.class, //
+    FICTest.class })
 public class AllWebserviceTests {
 }
diff -r 437ac768ed53 -r 8d45fed594e7 
src-test/src/org/openbravo/test/datasource/FICTest.java
--- a/src-test/src/org/openbravo/test/datasource/FICTest.java   Fri Jan 09 
11:54:38 2015 +0530
+++ b/src-test/src/org/openbravo/test/datasource/FICTest.java   Fri Jan 09 
07:48:24 2015 +0100
@@ -11,7 +11,7 @@
  * under the License. 
  * The Original Code is Openbravo ERP. 
  * The Initial Developer of the Original Code is Openbravo SLU 
- * All portions are Copyright (C) 2014 Openbravo SLU 
+ * All portions are Copyright (C) 2014-2015 Openbravo SLU 
  * All Rights Reserved. 
  * Contributor(s):  ______________________________________.
  ************************************************************************
@@ -19,14 +19,25 @@
 
 package org.openbravo.test.datasource;
 
+import static org.hamcrest.Matchers.empty;
+import static org.hamcrest.Matchers.not;
+import static org.hamcrest.Matchers.startsWith;
+import static org.junit.Assert.assertThat;
 import static org.junit.Assert.assertTrue;
 
+import java.text.SimpleDateFormat;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.TimeZone;
 
 import org.apache.commons.lang.StringUtils;
 import org.codehaus.jettison.json.JSONObject;
+import org.hibernate.criterion.Restrictions;
 import org.junit.Test;
+import org.openbravo.client.kernel.reference.DateUIDefinition;
+import org.openbravo.dal.service.OBCriteria;
+import org.openbravo.dal.service.OBDal;
+import org.openbravo.model.materialmgmt.cost.CostingRule;
 
 /**
  * Test cases for FormInitializationComponent
@@ -34,7 +45,7 @@
  * @author alostale
  * 
  */
-public class FICTest extends BaseDataSourceTestNoDal {
+public class FICTest extends BaseDataSourceTestDal {
 
   /**
    * Auxiliary Input for which SQL can't be evaluated on NEW and the value is 
correctly set by
@@ -58,4 +69,37 @@
     assertTrue("ORDERTYPE should have value",
         orderType.has("value") && 
StringUtils.isNotEmpty(orderType.getString("value")));
   }
+
+  /**
+   * Tests FIC doesn't change date-time value when row is retrieved to be 
edited
+   * 
+   * See issue #28541
+   */
+  @Test
+  public void dateTimeShouldntChange() throws Exception {
+    OBCriteria<CostingRule> qRule = 
OBDal.getInstance().createCriteria(CostingRule.class);
+    qRule.add(Restrictions.isNotNull(CostingRule.PROPERTY_STARTINGDATE));
+    qRule.setMaxResults(1);
+    assertThat(qRule.list(), not(empty()));
+
+    CostingRule rule = qRule.list().get(0);
+
+    Map<String, String> params = new HashMap<String, String>();
+    params.put("MODE", "EDIT");
+    params.put("_action", 
"org.openbravo.client.application.window.FormInitializationComponent");
+    params.put("TAB_ID", "6868B706DA8340158DE353A6C252A564"); // Costing Rules
+    params.put("ROW_ID", rule.getId());
+    String response = doRequest("/org.openbravo.client.kernel", params, 200, 
"POST");
+
+    String ficDateFromValue = new 
JSONObject(response).getJSONObject("columnValues")
+        .getJSONObject("Datefrom").getString("value");
+
+    // FIC returns date-time in UTC, let's convert actual date-time to UTC...
+    SimpleDateFormat utcFormatter = new DateUIDefinition().getFormat();
+    utcFormatter.setTimeZone(TimeZone.getTimeZone("UTC"));
+    String utcFormattedDateTime = utcFormatter.format(rule.getStartingDate());
+
+    // ...and compare it with the returned value
+    assertThat(ficDateFromValue, startsWith(utcFormattedDateTime));
+  }
 }

------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
Openbravo-commits mailing list
Openbravo-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openbravo-commits

Reply via email to