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.

1

qweb directives add days in date

By
kartik
on 10/12/15, 9:14 AM 1,293 views

hi i want to addition in date in odoo directives in odoov8

in reports i print invoice date using

<span t-field="o.date_invoice"/>;

now i want to add days in this date meansmy invoice date is 10/01/2015 and my pament term days is 15 so i want to add 15 days in date in report.xml file through qweb directives so output is 10/16/2015 (10/01/2015(mm/dd/yyyy) + 15days = 10/16/2015)

i get payment term days from this

<tr t-foreach="o.payment_term.line_ids" t-as="pl">

<td> <span t-field="pl.days"/> </td> 

</tr>

so how can i do addition in date in qweb directives

0
Jaydeep Barot (jar)
On 10/13/15, 2:41 AM

I have solved it with this line of codes. Try it to print in invoice report

<div t-esc="( datetime.datetime.strptime(o.date_invoice, '%Y-%m-%d %H:%M:%S') + datetime.timedelta(days=15) ).strftime('%m/%d/%Y')">
 

Kind Regards,

0
Micky
On 10/12/15, 5:16 PM

hi,

i have solved it with this line of codes. In my example i had adapted the report_saleorder.xml. 

<span t-set="d_delta" t-value="datetime.timedelta(days=17)"/>

<span t-set="d_dateorder" t-value="datetime.datetime.strptime(doc.date_order,'%Y-%m-%d %H:%M:%S')"/>

<span t-set="d_paydate" t-value="d_dateorder + d_delta"/>

<span t-esc="d_paydate.strftime('%d.%m.%Y')"/>

To use the datetime object you have to import the datetime object. --&gt; from datetime import datetime, timedelta this i have added to sale_report.py. 

best regards

i try with this code

but it gives following error ""'str' object has no attribute 'strptime'" while evaluating "o.date_invoice.strptime('%Y-%m-%d %H:%M:%S')"" while evaluating "translate_doc(doc_id, doc_model, 'partner_id.lang', 'account.report_without_prices_document')"
kartik
on 10/13/15, 1:04 AM

my code is

kartik
on 10/13/15, 1:05 AM
kartik
on 10/13/15, 1:06 AM

in my opinion you have to put your date_invoice into the braces of the strptime. Have look on the python website https://docs.python.org/2/library/time.html

Micky
on 10/13/15, 1:41 AM

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

2 follower(s)

Stats

Asked: 10/12/15, 9:14 AM
Seen: 1293 times
Last updated: 10/13/15, 2:42 AM