Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
10269 Lượt xem

I want to create a user defined filter to filter events ocurring in the next 7 days 

used the folowing code

[('date','<=', ((context_today()-datetime.timedelta(days=7)).strftime('%Y-%m-%d')))],[('date','>=', context_today())]

Didnt worked

I tried a simple

[['date', '>=', context_today()]]

and it dint worked either...

 

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I  also had same requirement, for 3 days...

So I used functional field say next_7th_date, which will calculated the date (in your case 7th day from date) and saved it in db...

Then  used it in XML search view like this

<filter name="next_7th_date"  domain="[('next_7th_date', '&gt;', current_date)]" ...../>

 

This w

Ảnh đại diện
Huỷ bỏ
Tác giả

Using the filter bellow is simpler and more flexible!

Câu trả lời hay nhất

For Events, there is no field date, you should use date_begin

https://www.dropbox.com/s/ghl9ij4unfno8zs/FilterOnEventsDates.mov?dl=0

[('date_begin','>=', ((context_today()).strftime('%Y-%m-%d'))), ('date_begin','<=', ((context_today()+datetime.timedelta(days=7)).strftime('%Y-%m-%d')))]

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

somehow we have to refresh to reload the filter...

under the user defined filters the following code works!

[
['date', '>=', context_today().strftime('%Y-%m-%d')],
['date', '<', (context_today() + datetime.timedelta(7)).strftime('%Y-%m-%d')],
]

With the advantage of having all the data. Filters are a more convenient way than xml search

Ảnh đại diện
Huỷ bỏ