Quantcast
Channel: OpenERP Help - Individual question feed
Viewing all articles
Browse latest Browse all 106

convert datetime to float - float_time

$
0
0
I used a float field with widget "float_time" to display a time. How I can convert datetime to float to display correctly in the widget?. I explain a little more my scenario, I have a field field 'start_date' which is datetime, I want that in the event "on_change" I set the time value in another field of type float that has the widget "float_time". 'start_date': fields.datetime('Fecha Inicio' , required = True), 'h_inicio': fields.float('Hora inicio', help="Hora inicio" , required = True), In view : Method on_change: def onchange_f_inicio(self, cr, uid, ids ,fecha_inicio): res = {'value':{}} fecha_ini = datetime.strptime(fecha_inicio, "%Y-%m-%d %H:%M:%S") user = self.pool.get('res.users').browse(cr, uid, uid) tz = pytz.timezone(user.tz) if user.tz else pytz.utc fecha_ini = pytz.utc.localize(fecha_ini).astimezone(tz) # convert start in user's timezone hora_inicio = "%s.%s" % (str(fecha_ini.hour) , str(fecha_ini.minute)) res['value']['h_inicio'] = round(float(hora_inicio),1) return res The only way that has worked is to convert the date 'start_date' in a string and then convert to a float to be the value returned by the method on_change. This form does not think it's the best, if I can help create a better way to thank you. thanks

Viewing all articles
Browse latest Browse all 106

Trending Articles