Odoo Help

Welcome!

This community 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.

0

Add days to time value in sales quotation

By
Phil74
on 3/6/13, 11:27 AM 2,571 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: 127.0.0.1 - - [06/Mar/2013 16:36:08] "POST /web/dataset/search_read HTTP/1.1" 200 -

Phil74
on 3/6/13, 11:39 AM
1

Andreas Brueckl

--Andreas Brueckl--
5056
| 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:

self.localcontext.update({
   '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.

Phil74
on 3/7/13, 5:13 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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