Skip to Content
Menu
This question has been flagged
1 Reply
20572 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

Avatar
Discard
Best Answer

<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>

Avatar
Discard
Author

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

Related Posts Replies Views Activity
0
Mar 15
6465
0
Mar 15
3783
14
May 22
46543
8
Mar 21
30346
1
Feb 24
5079