I have a model 'media.playlist':
class media_playlist(models.Model):
_name = 'media.playlist'
start = fields.Datetime('Start', required=True, help="Start Time", store=True)
stop = fields.Datetime('Stop', required=True, compute='get_stop', store=True, readonly=False, help="End Time")
@api.depends('start')
def get_stop(self):
from datetime import datetime, timedelta
for p in self:
if p.start:
p_start_date_obj = datetime.strptime(p.start, "%Y-%m-%d %H:%M:%S")
p.stop = p_start_date_obj + timedelta(hours=4)
I have a tree and a form view for this model and it all works ok and on record creation both fields get stored into a database using UTC timezone (which is the expected Odoo behavior).
Now, from my own javascript web view I somehow get the wrong values when I do the RPC call:
RPC.query({
model: 'media.playlist',
method: 'search_read',
args: [[['id','=',1],], ['id','start','stop']],
}).then(function (results) {
var playlist_view = new Playlist(self, {'playlist': result[0]});
playlist_view.appendTo(self.$el.find('#media_panel'));
});
A simple template to display the "Playlist" view:
<t t-name="Playlists">
<div>
<h4>Playlist</h4>
<t t-esc="widget.playlist['start']">
<t t-esc="widget.playlist['stop']">
</div>
</t>
So my problem is that these two fields (start & stop) get displayed in UTC (the same tz as stored in db). So what am I doing wrong? It works ok on Odoo tree and form views I created using xml, but not on my custom javascript views.