Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
20480 มุมมอง

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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

Related Posts ตอบกลับ มุมมอง กิจกรรม
0
มี.ค. 15
6318
0
มี.ค. 15
3666
14
พ.ค. 22
46289
How to make space in qweb report? แก้ไขแล้ว
8
มี.ค. 21
30162
1
ก.พ. 24
4948