This question has been flagged
3 Replies
9386 Views

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

 

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

Using the filter bellow is simpler and more flexible!

Best Answer

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')))]

Avatar
Discard
Author Best Answer

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

Avatar
Discard