[fix] problem with an on_change returning a datetime instead of a date
bzr revid: nicolas.vanhoren@openerp.com-20110901152224-1mcv25kdrbxb9zd1
This commit is contained in:
parent
55250f1006
commit
681af866e4
|
@ -1106,17 +1106,17 @@ openerp.base.form.FieldDatetime = openerp.base.form.Field.extend({
|
|||
focus: function() {
|
||||
this.$element.find('input').focus();
|
||||
},
|
||||
parse: openerp.base.str_to_datetime,
|
||||
format: openerp.base.datetime_to_str
|
||||
parse: openerp.base.auto_str_to_date,
|
||||
format: function(val) {
|
||||
return openerp.base.auto_date_to_str(val, this.field.type);
|
||||
}
|
||||
});
|
||||
|
||||
openerp.base.form.FieldDate = openerp.base.form.FieldDatetime.extend({
|
||||
init: function(view, node) {
|
||||
this._super(view, node);
|
||||
this.jqueryui_object = 'datepicker';
|
||||
},
|
||||
parse: openerp.base.str_to_date,
|
||||
format: openerp.base.date_to_str
|
||||
}
|
||||
});
|
||||
|
||||
openerp.base.form.FieldText = openerp.base.form.Field.extend({
|
||||
|
|
|
@ -45,7 +45,7 @@ openerp.base.format_value = function (value, descriptor, value_if_empty) {
|
|||
return value[1];
|
||||
case 'datetime':
|
||||
if (typeof(value) == "string")
|
||||
value = auto_str_to_date(value, descriptor.type);
|
||||
value = openerp.base.auto_str_to_date(value);
|
||||
try {
|
||||
return value.toString(_.sprintf("%s %s", Date.CultureInfo.formatPatterns.shortDate,
|
||||
Date.CultureInfo.formatPatterns.longTime));
|
||||
|
@ -55,7 +55,7 @@ openerp.base.format_value = function (value, descriptor, value_if_empty) {
|
|||
return value;
|
||||
case 'date':
|
||||
if (typeof(value) == "string")
|
||||
value = auto_str_to_date(value, descriptor.type);
|
||||
value = openerp.base.auto_str_to_date(value);
|
||||
try {
|
||||
return value.toString(Date.CultureInfo.formatPatterns.shortDate);
|
||||
} catch (e) {
|
||||
|
@ -63,7 +63,7 @@ openerp.base.format_value = function (value, descriptor, value_if_empty) {
|
|||
}
|
||||
case 'time':
|
||||
if (typeof(value) == "string")
|
||||
value = auto_str_to_date(value, descriptor.type);
|
||||
value = openerp.base.auto_str_to_date(value);
|
||||
try {
|
||||
return value.toString(Date.CultureInfo.formatPatterns.longTime);
|
||||
} catch (e) {
|
||||
|
@ -138,16 +138,29 @@ openerp.base.parse_value = function (value, descriptor, value_if_empty) {
|
|||
return value;
|
||||
};
|
||||
|
||||
var auto_str_to_date = function(value, type) {
|
||||
openerp.base.auto_str_to_date = function(value, type) {
|
||||
try {
|
||||
return openerp.base.str_to_datetime(value);
|
||||
} catch(e) {}
|
||||
try {
|
||||
return openerp.base.str_to_date(value);
|
||||
} catch(e) {}
|
||||
try {
|
||||
return openerp.base.str_to_time(value);
|
||||
} catch(e) {}
|
||||
throw "'" + value + "' is not a valid date, datetime nor time"
|
||||
};
|
||||
|
||||
openerp.base.auto_date_to_str = function(value, type) {
|
||||
switch(type) {
|
||||
case 'datetime':
|
||||
return openerp.base.str_to_datetime(value);
|
||||
return openerp.base.datetime_to_str(value);
|
||||
case 'date':
|
||||
return openerp.base.str_to_date(value);
|
||||
return openerp.base.date_to_str(value);
|
||||
case 'time':
|
||||
return openerp.base.str_to_time(value);
|
||||
return openerp.base.time_to_str(value);
|
||||
default:
|
||||
throw "'" + value + "' is not a valid date, datetime nor time"
|
||||
throw type + " is not convertible to date, datetime nor time"
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue