From bccc6c4a1d57f34554cc4f5eb70c0effc5ff866e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A0=20Tarroja=20Caubet?= Date: Thu, 2 Sep 2021 23:30:57 +0200 Subject: [PATCH] Cast Date and Time field value to the correct type when checking for modification issue10655 review352481002 (grafted from b03d7d7e0225a0a582eae5ddf0f79324760f58c6) --HG-- branch : 6.0 --- src/sao.js | 15 ++++++++++----- src/view/form.js | 20 ++++++++++++++++++-- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/sao.js b/src/sao.js index e4bea63646..9fcad3e341 100644 --- a/src/sao.js +++ b/src/sao.js @@ -262,15 +262,20 @@ var Sao = {}; } 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 --git a/src/view/form.js b/src/view/form.js index eb6231be8e..9296c42c31 100644 --- a/src/view/form.js +++ b/src/view/form.js @@ -1692,7 +1692,8 @@ function eval_pyson(value){ }, 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())); } @@ -1711,7 +1712,13 @@ function eval_pyson(value){ 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, { @@ -1730,6 +1737,9 @@ function eval_pyson(value){ return this._default_format; } }, + cast: function(value){ + return value; + }, }); Sao.View.Form.Time = Sao.class_(Sao.View.Form.Date, { @@ -1754,6 +1764,12 @@ function eval_pyson(value){ 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, {