Odoo Help


This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


[V8] How to add timestamp to a processed order and calculate the time?

on 5/21/15, 8:22 PM 572 views

I've created a timedate field to record when a pos.order was marked as done in production. What is the correct way to populate it?

Is on pos.order model, and should be triggered (and compiled) when another filed (on pos.oder too) already working and called by a button using a server action. And how I should calculated it (fields.function) to see how much time is passed from the creation of the order?

On 5/27/15, 12:36 PM

Ok. Adding the time was easy polulating a datetime field linked to a server action using a python expression


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?


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


But the fields are not updated. I tried with different type of fields (char, float, datetime) but I'm still stuck.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)


Asked: 5/21/15, 8:22 PM
Seen: 572 times
Last updated: 6/2/15, 5:00 PM