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

Hi.

I have a filter name today with the next value:

<filter string="Today" domain="[('date','>=',((context_today())).strftime('%%Y-%%m-%%d 00:00:00')), ('date', '<=',((context_today())).strftime('%%Y-%%m-%%d 23:59:59'))]"/>

The date field is datetime and the filter work good. The filter return only values from today.

If i save the filter as default filter, openerp save the actual date and the filter not work tomorrow or other day because the date is saved instead of context_today().

Any method to save a filter with the context_today instead of his value?

Thanks. Best regards.

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

Don't use strftime with hard-coded times. It doesn't take different time zones into account. Instead, use this

<filter name="today" string="Today" 
domain="[('date','>=', datetime.datetime.combine(context_today(), datetime.time(0,0,0))),
('date','<=', datetime.datetime.combine(context_today(), datetime.time(23,59,59)))]" />

For example, I'm on UTC+3 now and when I set the min_date of a stock.picking to 2015-05-14 02:00, it's saved to the database as 2015-05-13 23:00. Using strftime in the domain will only work if the min_date is 2015-05-14 03:00 (=2015-05-14 00:00 UTC).

See this commit and this issue.

อวตาร
ละทิ้ง

Thank you for sharing this. It has been very useful for me.

คำตอบที่ดีที่สุด

Try it this way:

<filter string="Today" domain="[('date','&lt;=',time.strftime('%Y-%m-%d 23:59:59')),('date','&gt;=',time.strftime('%Y-%m-%d 00:00:00'))]"/>

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

You will need to go to menu Settings > Technical > User Interface > User-defined filters

There you will see your saved filters in which date already set as specific date.

You need to make the domain here more generic, i.e, 

['date_payment', '<=', time.strftime('%Y-%m-%d 23:59:59')]

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

Solution from Miku Laitinen works perfect.

I'm using v10 but it seems it doesn't matter wich version.

Thanks a lot.

อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

if any answers is given. This can be cataloged as bug.

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
2
พ.ย. 23
3056
filter with related model field แก้ไขแล้ว
1
ต.ค. 20
4804
change search filter แก้ไขแล้ว
2
พ.ย. 16
4172
Search with functional fields แก้ไขแล้ว
4
มี.ค. 15
21105
1
มี.ค. 15
13627