Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
5909 Widoki

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?


Awatar
Odrzuć
Autor Najlepsza odpowiedź

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.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
lut 18
3368
0
cze 15
5060
1
lip 19
4372
1
cze 16
4594
0
cze 16
3824