Odoo Help

0

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

By
FEDERICO LEONI
on 5/21/15, 8:22 PM 986 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?


0
FEDERICO LEONI
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

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.

About This Community

This platform 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.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

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