Ok. Adding the time was easy polulating a datetime field linked to a server action using a python expression
datetime.datetime.now()
Now, how to translate this script
# Credits for the original script to Ken Cochrane:
# http://stackoverflow.com/questions/2788871/python-date-difference-in-minutes/6879077#6879077
from datetime import datetime
import time
fmt = '%m/%d/%Y %H:%M:%S'
starttime = '05/27/2015 16:43:38' #pos.order.order_date here
endtime = '05/27/2015 16:47:41' #pos.order.my_custom_field here
d1 = datetime.strptime(starttime, fmt)
d2 = datetime.strptime(endtime, fmt)
# convert to unix timestamp
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
# they are now in seconds, subtract and then divide by 60 to get minutes.
print int(d2_ts-d1_ts) / 60
to calculate the diff (in minutes) between date_order and my custom field on pos.order on Odoo?
Edit:
This is the script I put on my model:
def on_change_kot_time(self,cr,user,ids,date_order,x_kot_time2,context=None):
fmt = '%m/%d/%Y %H:%M:%S'
d1 = datetime.strptime(date_order, fmt)
d2 = datetime.strptime(x_kot_time2, fmt)
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
tempo = int(d2_ts-d1_ts) / 60
res = {
'value': {
'x_minutes': tempo,
}
}
return res
I've edit the fields date_order,x_kot_time2 and x_minutes on my xml wiew with the on_change call
on_change="on_change_kot_time(date_order,x_kot_time2)
But the fields are not updated. I tried with different type of fields (char, float, datetime) but I'm still stuck.