Skip to Content
Menu
This question has been flagged
1 Odpoveď
7265 Zobrazenia

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
Zrušiť

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 -

Best Answer

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
Zrušiť
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.

Related Posts Replies Zobrazenia Aktivita
1
mar 15
6064
0
máj 20
3207
1
máj 20
17912
3
mar 16
3109
2
mar 15
5382