Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
7218 Vistas

On my sales quotation report, I convert and format the create_date to present it as the order date. To do so I use:

time.strftime('%d %B %Y', time.strptime(so.create_date, '%Y-%m-%d %H:%M:%S'))

I would also like to show the delivery date by adding 60 days to the create_date. To do this I tried the following:

[[ time.strftime("%d %B %Y",(datetime.strptime(so.create_date,"%Y-%m-%d %H:%M:%S") + timedelta(days=60)).timetuple()) ]]

But this doesn't return anything in the report, even though it works fine when tested from the python command line.

My python test:

>>> print(time.strftime('%d %B %Y',(datetime.strptime('2013-01-01 08:38:01', '%Y-%m-%d %H:%M:%S') + timedelta(days=60)).timetuple()))

which returns:

02 mars 2013

I created a formula in the report (using OpenOffice Writer) and simply replaced the hardcoded date with the field so.create_date.

When requesting the sale quotation report from openerp, this field is always empty.

Any idea why it works from python and not from the report?

Avatar
Descartar

What say the OpenERP logs?

Autor

2013-03-06 16:36:08,292 7324 INFO ? werkzeug: 127.0.0.1 - - [06/Mar/2013 16:36:08] "POST /web/dataset/search_read HTTP/1.1" 200 -

Mejor respuesta

I assume that you are using v6.0. The reason is that within the parser of the report, the objects datetime and timedelta are not available and therefore can not be used.

If you want to use them you have to add them to the localcontext in the report file.

For the sale order you have to update the file: addons/sale/report/sale_order.py:

self.localcontext.update({
   'time': time,
   'datetime': datetime,
   'timedelta': timedelta,
})

You also have to import the required libs for datetime and timedelta.

Avatar
Descartar
Autor

Andreas, thanks so much, this has driven me crazy for so long! I was missing the self.localcontext.update with the datetime and timedelta (I am new to python). I had the rest and my formula works fine now.

Publicaciones relacionadas Respuestas Vistas Actividad
1
mar 15
6022
0
may 20
3168
1
may 20
17839
3
mar 16
3087
2
mar 15
5348