Odoo Help


[V8]Use on_change to calculate a timedate field?

on 6/2/15, 2:34 PM 845 views

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


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.

on 6/6/15, 11:54 AM

Yenthe, I have no idea on how to do that.

on 6/7/15, 7:48 PM

Still stuck. I played around with the Chrome console but I can't see any error. Any idea?

on 6/18/15, 5:16 PM

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/

on 6/19/15, 2:51 AM

Tried with:

import logging

_logger = logging.getLogger(__name__)
LOG_FILENAME = '/home/effe/divina_log'
And at the end of the function:
	_logger.debug("date_order value : %r", d1)
	_logger.debug("end_date value : %r", d2)
	_logger.debug("date_order_timestamp value : %r", d1_ts)
	_logger.debug("end_date_timestamp value : %r", d2_ts)
	_logger.debug("timekot value : %r", timekot)
	_logger.debug("minutes value : %r", minutes)
But the log file remains blank.
on 6/19/15, 11:30 AM

Please note I've changed the name of the variables. Again it works fine directly on pycharm with psycopg2.

on 6/19/15, 11:33 AM

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.

on 6/19/15, 7:50 PM

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.


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)


Asked: 6/2/15, 2:34 PM
Seen: 845 times
Last updated: 6/19/15, 7:50 PM