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

Correct way to check if date is empty in field and print current date if date field is empty?

By
Yenthe
on 1/28/15, 3:44 AM 3,201 views

Hi guys

I've been trying to make a QWeb report which gets a date field from my model. If the datefield is empty (so no date supplied) the QWeb report should print the current date.

What I've tried:

<p>
           <t t-if="o.print_date == ''">
            No date supplied: <t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate)"/>
           </t>
           <t t-if="o.print_date != null">
            Date: <span t-field="o.print_date"/>
           </t>
        </p>

There are two problems with my current code though.
1) The field o.print_date is always validated as not null, so it always goes in the t-if statement from <t t-if="o.print_date != null">
2) If it would ever get in to the != null statement the code <t t-esc="new Date().toString(Date.CultureInfo.formatPatterns.shortDate)"/> will not work. 

So my question:
1) How can I check for the datefield to be empty? 
2) How can I print the date from today without having it in any field, so directly fetch it in the QWeb report

3
Sajad KK
On 1/28/15, 5:15 AM

<p>
           <t t-if="o.print_date is False">
            No date supplied: <t t-esc="time.strftime('%Y-%m-%d')"/>
           </t>
           <t t-if="o.print_date is not False">
            Date: <span t-field="o.print_date"/>
           </t>
        </p>

Hmm how stupid that I forgot to check it with 'True' or 'False'.. should have known that. This works like a charm. Accepted & upvoted!

Yenthe
on 1/28/15, 5:21 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

1 follower(s)

Stats

Asked: 1/28/15, 3:44 AM
Seen: 3201 times
Last updated: 3/16/15, 8:10 AM