Computed field float_time to calculate the time difference between two dates:
fields:
x_studio_from_date_time - datetime
x_studio_to_date_time - datetime
x_studio_duration - float_time
dependencies: x_studio_from_date_time, x_studio_to_date_time
Computed Field:
for record in self:
if record.x_studio_from_date_time and record.x_studio_to_date_time:
t1=datetime.strptime(str(record.x_studio_from_date_time),'%Y-%m-%d %H:%M:%S')
t2=datetime.strptime(str(record.x_studio_to_date_time),'%Y-%m-%d %H:%M:%S')
t3=t2-t1
record['x_studio_duration']=str(t3.days)
ERROR:
ValueError: <class 'AttributeError'>: "'x_ios' object has no attribute 'str'" while evaluating "for r in self:\n if r.x_studio_to_date_time and r.x_studio_from_date_time:\n x_studio_from_date_time = r.str(x_studio_from_date_time)\n x_studio_to_date_time = r.str(x_studio_to_date_time)\n frm_dt = datetime.datetime.strptime(r.x_studio_from_date_time, '%Y-%m-%d %H:%M:%S.%f')\n to_dt = datetime.datetime.strptime(r.x_studio_to_date_time, '%Y-%m-%d %H:%M:%S.%f')\n diff = float(to_dt) - float(frm_dt)\n r['x_studio_duration']=r.float(diff)\n"