[FIX] web: backport datetime.toJSON() so we can return local datetimes in search domains

This fix adds the toJSON() method to datetime.datetime,
so domain expressions can use datetime values directly,
without having to compute the stringified version
with convoluted strftime() and timezone calculations.

The datetime results are sent down to the JSON-RPC
level where the JSON.stringify() serialization will
convert them to UTC string, to be deserialized
properly as UTC datetime values on the server side.

Thanks to this we can use the browser's local midnight
timestamp in a filter expression, for example like this:

`datetime.datetime.combine(context_today(), datetime.time(0,0,0))`

and get the expected result regardless of the user/browser's
timezone.

related to issue #2972 and pull request #2914 and #6229

(Next commit will fix them)

opw-621282
This commit is contained in:
Nicolas Lempereur 2015-04-13 14:39:14 +02:00 committed by Olivier Dony
parent 5267e3a158
commit 76881fb226
1 changed files with 11 additions and 1 deletions

View File

@ -412,7 +412,17 @@ openerp.web.pyeval = function (instance) {
py.PY_getAttr(args.time, 'minute'),
py.PY_getAttr(args.time, 'second')
]);
})
}),
toJSON: function () {
return new Date(
this.year,
this.month - 1,
this.day,
this.hour,
this.minute,
this.second,
this.microsecond / 1000);
},
});
datetime.date = py.type('date', null, {
__init__: function () {