diff options
| author | Géry Debongnie <ged@odoo.com> | 2017-02-24 14:35:39 +0100 |
|---|---|---|
| committer | Aaron Bohy <aab@odoo.com> | 2017-04-11 19:44:38 +0200 |
| commit | da4e653695cceb1d3cbd9342b3cd830734c21fee (patch) | |
| tree | 9bdf4df349b00c433ad84d53d4239a3e406c28c0 /addons/web/static/src | |
| parent | 4a612171b3bf85f2902c582fcc658eea668a732e (diff) | |
[FIX] web: various fixes for date and datetime in client
The field_utils date method have been modified recently, and the idea
behind those changes is that the BasicModel keeps at all time a moment
instance as its internal representation of a date or datetime.
But the parse and format methods did not properly support unset dates,
so we have to slighlty change them to support the case where their values is
not set.
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/fields/field_utils.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/addons/web/static/src/js/fields/field_utils.js b/addons/web/static/src/js/fields/field_utils.js index 61e31aeb66f..daebfdb37f4 100644 --- a/addons/web/static/src/js/fields/field_utils.js +++ b/addons/web/static/src/js/fields/field_utils.js @@ -36,20 +36,26 @@ function format_char(value) { } /** - * @params {Moment} + * @params {Moment|false} * @returns {string} */ function format_date(value) { + if (!value) { + return ""; + } var l10n = core._t.database.parameters; var date_format = time.strftime_to_moment_format(l10n.date_format); return value.format(date_format); } /** - * @params {Moment} + * @params {Moment|false} * @returns {string} */ function format_datetime(value) { + if (!value) { + return ""; + } var l10n = core._t.database.parameters; var date_format = time.strftime_to_moment_format(l10n.date_format); var time_format = time.strftime_to_moment_format(l10n.time_format); @@ -160,9 +166,12 @@ function format_selection(value, field) { * The method toJSON return the formated value to send value server side * * @params {string} - * @returns {Moment} Moment date object + * @returns {Moment|false} Moment date object */ function parse_date(value) { + if (!value) { + return false; + } var date_pattern = time.strftime_to_moment_format(core._t.database.parameters.date_format); var date_pattern_wo_zero = date_pattern.replace('MM','M').replace('DD','D'); var date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true); @@ -188,9 +197,12 @@ function parse_date(value) { * The method toJSON return the formated value to send value server side * * @params {string} - * @returns {Moment} Moment date object + * @returns {Moment|false} Moment date object */ function parse_datetime(value) { + if (!value) { + return false; + } var date_pattern = time.strftime_to_moment_format(core._t.database.parameters.date_format), time_pattern = time.strftime_to_moment_format(core._t.database.parameters.time_format); var date_pattern_wo_zero = date_pattern.replace('MM','M').replace('DD','D'), |
