changeset b03d7d7e0225 in sao:default
details: https://hg.tryton.org/sao?cmd=changeset&node=b03d7d7e0225
description:
        Cast Date and Time field value to the correct type when checking for 
modification

        issue10655
        review352481002
diffstat:

 src/sao.js       |  15 ++++++++++-----
 src/view/form.js |  20 ++++++++++++++++++--
 2 files changed, 28 insertions(+), 7 deletions(-)

diffs (80 lines):

diff -r a7d07e635e86 -r b03d7d7e0225 src/sao.js
--- a/src/sao.js        Thu Sep 02 23:17:33 2021 +0200
+++ b/src/sao.js        Thu Sep 02 23:30:57 2021 +0200
@@ -262,15 +262,20 @@
         }
         datetime.isDateTime = true;
         datetime.local();
+        datetime.todate = function() {
+            return Sao.Date(this.year(), this.month(), this.date());
+        };
+        datetime.totime = function() {
+            return Sao.Time(
+                this.hour(), this.minute(), this.second(), this.millisecond());
+        };
         return datetime;
     };
 
     Sao.DateTime.combine = function(date, time) {
-        var datetime = date.clone();
-        datetime.set({hour: time.hour(), minute: time.minute(),
-            second: time.second(), millisecond: time.millisecond()});
-        datetime.isDateTime = true;
-        return datetime;
+        return Sao.DateTime(
+            date.year(), date.month(), date.date(),
+            time.hour(), time.minute(), time.second(), time.millisecond());
     };
 
     Sao.DateTime.min = moment(new Date(-100000000 * 86400000)).local();
diff -r a7d07e635e86 -r b03d7d7e0225 src/view/form.js
--- a/src/view/form.js  Thu Sep 02 23:17:33 2021 +0200
+++ b/src/view/form.js  Thu Sep 02 23:30:57 2021 +0200
@@ -1701,7 +1701,8 @@
         },
         get modified() {
             if (this.record && this.field) {
-                var field_value = this.field.get_client(this.record);
+                var field_value = this.cast(
+                    this.field.get_client(this.record));
                 return (JSON.stringify(field_value) !=
                     JSON.stringify(this.get_value()));
             }
@@ -1720,7 +1721,13 @@
                     this.icon.show();
                 }
             }
-        }
+        },
+        cast: function(value){
+            if (value && value.isDateTime) {
+                value = value.todate();
+            }
+            return value;
+        },
     });
 
     Sao.View.Form.DateTime = Sao.class_(Sao.View.Form.Date, {
@@ -1739,6 +1746,9 @@
                 return this._default_format;
             }
         },
+        cast: function(value){
+            return value;
+        },
     });
 
     Sao.View.Form.Time = Sao.class_(Sao.View.Form.Date, {
@@ -1763,6 +1773,12 @@
                 return this._default_format;
             }
         },
+        cast: function(value){
+            if (value && value.isDateTime) {
+                value = value.totime();
+            }
+            return value;
+        },
     });
 
     Sao.View.Form.TimeDelta = Sao.class_(Sao.View.Form.Widget, {

Reply via email to