summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2016-11-30 13:56:20 +0100
committerNicolas Martinelli <nim@odoo.com>2016-11-30 13:56:20 +0100
commite5cad9a45e2f2eb137e2c2746e87bb36e25b2dbd (patch)
tree9fca06c26095883b1d384529a3bbe0f5c504d204
parent21148fb46f03cd65f0e87b50e5b34cd81bb0c26b (diff)
[FIX] web: date autocompletion
When a user fills partially a date or datetime field, the system will somehow autocomplete the value entered. For example, if the user enters "11//11" then clicks on the Tab key, it will be completed as "11/11/0000". However, the year 0000 is not recognized in Python, and this causes a crash upon saving. opw-695035
-rw-r--r--addons/web/static/src/js/framework/formats.js12
1 files changed, 10 insertions, 2 deletions
diff --git a/addons/web/static/src/js/framework/formats.js b/addons/web/static/src/js/framework/formats.js
index 8a5a8ffedb7..90cecd5398d 100644
--- a/addons/web/static/src/js/framework/formats.js
+++ b/addons/web/static/src/js/framework/formats.js
@@ -164,16 +164,24 @@ function parse_value (value, descriptor, value_if_empty) {
if (datetime.isValid())
return time.datetime_to_str(datetime.toDate());
datetime = moment(value, [date_pattern + ' ' + time_pattern, date_pattern_wo_zero + ' ' + time_pattern_wo_zero, moment.ISO_8601]);
- if (datetime.isValid())
+ if (datetime.isValid()) {
+ if (datetime.year() === 0) {
+ datetime.year(moment.utc().year());
+ }
return time.datetime_to_str(datetime.toDate());
+ }
throw new Error(_.str.sprintf(_t("'%s' is not a correct datetime"), value));
case 'date':
var date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true);
if (date.isValid())
return time.date_to_str(date.toDate());
date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601]);
- if (date.isValid())
+ if (date.isValid()) {
+ if (date.year() === 0) {
+ date.year(moment.utc().year());
+ }
return time.date_to_str(date.toDate());
+ }
throw new Error(_.str.sprintf(_t("'%s' is not a correct date"), value));
case 'time':
var _time = moment(value, [time_pattern, time_pattern_wo_zero, moment.ISO_8601], true);