Odoo Help


Add days to time value in sales quotation

on 3/6/13, 11:27 AM 3,338 views

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?

What say the OpenERP logs?

Andreas Brueckl
on 3/6/13, 11:30 AM

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

on 3/6/13, 11:39 AM

Andreas Brueckl

--Andreas Brueckl--

| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/6/13, 1:06 PM

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:

   'time': time,
   'datetime': datetime,
   'timedelta': timedelta,

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

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.

on 3/7/13, 5:13 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

0 follower(s)


Asked: 3/6/13, 11:27 AM
Seen: 3338 times
Last updated: 3/16/15, 8:10 AM