I'm trying to calculate how much time expressed in minutes passed from the creation of a pos.order till the end on a work center. I'm inherit the point_of_sale with a custom module:
class pos_order(osv.Model): _inherit = 'pos.order'
def on_change_kot_time(self,cr,user,ids,date_order,x_kot_time,context=None):
fmt = '%m/%d/%Y %H:%M:%S'
d1 = datetime.strptime(date_order, fmt)
d2 = datetime.strptime(x_kot_time, fmt)
d1_ts = time.mktime(d1.timetuple())
d2_ts = time.mktime(d2.timetuple())
timekot = int(d2_ts-d1_ts) / 60
res = {
'value': {
'x_minutes': timekot,
}
}
return res
but calling the definition with
<field name="field" on_change="on_change_kot_time(date_order,x_kot_time)/>
on pos.order for the field date_order and my two custom fields (x_kot_time and x_minutes) didn't out the result and rise no errors. Just a side note: the x_kot_time is a timedate populated by a (working) server action with the python expression
datetime.datetime.now()
What I'm missing?
Have you tried adding alerts in your JS to see what is inside your variables and if it even goes off? I can't see any explicit problem at the moment. Try to debug your values to see if those methods are actually triggered and see what is in the variables.
Yenthe, I have no idea on how to do that.
Still stuck. I played around with the Chrome console but I can't see any error. Any idea?
You could try with a simple window.alert? And if you want to do debugging/logging in Python, this tutorial works great: http://www.mindissoftware.com/2014/09/07/Odoo-logging-configuration-usage-implementation/
Tried with:
And at the end of the function: But the log file remains blank.Please note I've changed the name of the variables. Again it works fine directly on pycharm with psycopg2.
I give up. In less than an hour I create a new .py that is listening to the db and update it out from Odoo. No issues so far after processing more than 500 orders (+/- 900 rows) while using Odoo at the same time. I'm sorry to say that even with the new "skin" Odoo documentation is really inadequate.