Ir al contenido
Menú
Se marcó esta pregunta

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?

Avatar
Descartar

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.

Autor

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

Autor

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/

Autor

Tried with:

import logging

_logger = logging.getLogger(__name__)
LOG_FILENAME = '/home/effe/divina_log'
logging.basicConfig(filename=LOG_FILENAME,level=logging.DEBUG)
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.
Autor

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

Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
1
jun 15
4777
1
jun 15
5905
1
jul 19
4369
1
jun 16
4593
0
jun 16
3824