details:   https://code.openbravo.com/erp/devel/pi/rev/59d8a1189664
changeset: 35788:59d8a1189664
user:      Carlos Aristu <carlos.aristu <at> openbravo.com>
date:      Thu May 16 14:01:42 2019 +0200
summary:   fixes bug 40829: Can't save date taken from picker of 
DateTime_From/To fields

   It was not possible to save a date taken from the date picker of those 
fields using DateTime_From/To references. This is because the 
JsonToDataConverter expects a date time value to parse, but instead a plain 
date is received.

  The reason why a date was being received is because as this references are 
configured to not show the time (showTime: false), its date picker builds a 
logical date rather than a specific datetime value.

  To fix the problem we are setting the date received from the picker to be not 
logical, this way dates will be serialized to the expected DateTime value when 
sending the data to the Datasource in order to save/update the record.

diffstat:

 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js
 |  23 +++++----
 1 files changed, 13 insertions(+), 10 deletions(-)

diffs (40 lines):

diff -r 2e0c74eeeea1 -r 59d8a1189664 
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js
--- 
a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js
    Thu May 16 12:11:51 2019 +0200
+++ 
b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/formitem/ob-formitem-datetime.js
    Thu May 16 14:01:42 2019 +0200
@@ -281,23 +281,26 @@
 // It has the value of the current selected date at 00:00:00
 isc.ClassFactory.defineClass('OBDateTimeFromDateItem', isc.OBDateTimeItem);
 
-// == OBDateItem properties ==
+// == OBDateTimeFromDateItem properties ==
 isc.OBDateTimeFromDateItem.addProperties({
   showTime: false,
-  fixedTime: '00:00:00'
+  fixedTime: '00:00:00',
+  pickerDataChanged: function (picker) {
+    if (picker.chosenDate && picker.chosenDate.logicalDate) {
+      // The picker is returning a logical date because this class is defined 
to not show the time
+      // Remove the logicalDate flag because the value to be saved should be a 
datetime value
+      delete picker.chosenDate.logicalDate;
+    }
+    this.Super('pickerDataChanged', arguments);
+  }
 });
 
 // == OBDateTimeToDateItem ==
 // OBDateTimeToDateItem inherits from OBDateTimeItem
 // It has the value of the next day of the selected date at 00:00:00
-isc.ClassFactory.defineClass('OBDateTimeToDateItem', isc.OBDateTimeItem);
-
-// == OBDateItem properties ==
-isc.OBDateTimeToDateItem.addProperties({
-  showTime: false,
-  fixedTime: '00:00:00'
-});
-
+// Note that the logic to calculate the next day is not implemented here
+// For the moment, that logic should be implemented where needed
+isc.ClassFactory.defineClass('OBDateTimeToDateItem', 
isc.OBDateTimeFromDateItem);
 
 // == OBDateTimeToDateItem ==
 // OBAbsoluteDateTimeItem inherits from OBDateTimeItem


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

Reply via email to