summaryrefslogtreecommitdiff
path: root/addons/web/static
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-05-13 14:08:51 +0200
committerChristophe Simonis <chs@odoo.com>2016-05-13 14:08:51 +0200
commit7f2a9e77b6dbe65e3977f8a3b15de1785bc5d7d3 (patch)
tree9a6232b1dcf1f0435b1332c126a8d9cfdc683e64 /addons/web/static
parent89873cbed5fb31547843a7a135145d46986431af (diff)
parentdcab356b38aad5d6c7940c0211a3a940a8be9a65 (diff)
[MERGE] forward port of branch 9.0 up to dcab356
Diffstat (limited to 'addons/web/static')
-rw-r--r--addons/web/static/src/js/framework/formats.js6
-rw-r--r--addons/web/static/src/js/views/form_widgets.js8
-rw-r--r--addons/web/static/src/js/views/search_inputs.js12
-rw-r--r--addons/web/static/test/search.js4
4 files changed, 22 insertions, 8 deletions
diff --git a/addons/web/static/src/js/framework/formats.js b/addons/web/static/src/js/framework/formats.js
index 4b5ff8b4048..52a2fa5b0b0 100644
--- a/addons/web/static/src/js/framework/formats.js
+++ b/addons/web/static/src/js/framework/formats.js
@@ -160,17 +160,17 @@ function parse_value (value, descriptor, value_if_empty) {
case 'progressbar':
return parse_value(value, {type: "float"});
case 'datetime':
- var datetime = moment(value, [date_pattern + ' ' + time_pattern, date_pattern_wo_zero + ' ' + time_pattern_wo_zero], true);
+ var datetime = moment(value, [date_pattern + ' ' + time_pattern, date_pattern_wo_zero + ' ' + time_pattern_wo_zero, moment.ISO_8601], true);
if (datetime.isValid())
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], true);
+ var date = moment(value, [date_pattern, date_pattern_wo_zero, moment.ISO_8601], true);
if (date.isValid())
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], true);
+ var _time = moment(value, [time_pattern, time_pattern_wo_zero, moment.ISO_8601], true);
if (_time.isValid())
return time.time_to_str(_time.toDate());
throw new Error(_.str.sprintf(_t("'%s' is not a correct time"), value));
diff --git a/addons/web/static/src/js/views/form_widgets.js b/addons/web/static/src/js/views/form_widgets.js
index 1214f6e2ce3..b33177eb1d5 100644
--- a/addons/web/static/src/js/views/form_widgets.js
+++ b/addons/web/static/src/js/views/form_widgets.js
@@ -455,7 +455,13 @@ var FieldCharDomain = common.AbstractField.extend(common.ReinitializeFieldMixin,
if (this.get('value')) {
var model = this.options.model || this.field_manager.get_field_value(this.options.model_field);
- var domain = pyeval.eval('domain', this.get('value'));
+ try{
+ var domain = pyeval.eval('domain', this.get('value'));
+ }
+ catch(e){
+ this.do_warn(_t('Error: Bad domain'), _t('The domain is wrong.'));
+ return;
+ }
var ds = new data.DataSetStatic(self, model, self.build_context());
ds.call('search_count', [domain]).then(function (results) {
self.$('.o_count').text(results + _t(' selected records'));
diff --git a/addons/web/static/src/js/views/search_inputs.js b/addons/web/static/src/js/views/search_inputs.js
index 9d08a537e9d..edeffd874b0 100644
--- a/addons/web/static/src/js/views/search_inputs.js
+++ b/addons/web/static/src/js/views/search_inputs.js
@@ -341,7 +341,17 @@ var DateField = Field.extend(/** @lends instance.web.search.DateField# */{
return time.date_to_str(facetValue.get('value'));
},
complete: function (needle) {
- var m = moment(needle);
+ // Make sure the needle has a correct format before the creation of the moment object. See
+ // issue https://github.com/moment/moment/issues/1407
+ var t, v;
+ try {
+ t = (this.attrs && this.attrs.type === 'datetime') ? 'datetime' : 'date';
+ v = formats.parse_value(needle, {'widget': t});
+ } catch (e) {
+ return $.when(null);
+ }
+
+ var m = moment(v, t === 'datetime' ? 'YYYY-MM-DD HH:mm:ss' : 'YYYY-MM-DD');
if (!m.isValid()) { return $.when(null); }
var d = m.toDate();
var date_string = formats.format_value(d, this.attrs);
diff --git a/addons/web/static/test/search.js b/addons/web/static/test/search.js
index 4f35801cb10..d163913b0f4 100644
--- a/addons/web/static/test/search.js
+++ b/addons/web/static/test/search.js
@@ -643,7 +643,7 @@ odoo.define_section('search.completions', ['web.search_inputs', 'web.SearchView'
var view = {inputs: []};
var f = new DateField(
{attrs: {string: "Dummy"}}, {type: 'datetime'}, view);
- return f.complete('2012-05-21T21:21:21')
+ return f.complete('2012-05-21T21:21:21Z')
.done(function (completions) {
assert.equal(completions.length, 1, "should provide a single completion");
var c = completions[0];
@@ -1615,5 +1615,3 @@ odoo.define_section('search.advanced', ['web.search_inputs', 'web.SearchView', '
});
});
-
-