Skip to Content
Menu
This question has been flagged
1 Reply
1655 Views

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"

Avatar
Discard
Best Answer

Hi,

In the error message it seems that you are calling something like r.str(x_studio_from_date_time)  , suppose if r is a record of model sale.order, the error message says that there is no function named str in the corresponding model. So either you have to define such a function in your model or remove that call. 

Also you can tell what exactly you are looking to do. If you are looking to convert a value into string, you can do it like this, str(variable).


Thanks

Avatar
Discard
Author

Thank you Niyas.