Skip to Content
Menu
This question has been flagged

Hi,

I am creating filter strings that works perfect according to these instructions:

http://odoobyriyasshon.blogspot.com/2015/07/search-view-filters-in-odoo.html?m=1

But, I also want to create a relative filter, that can show what have happened in between.

Eg. I have been playoung around with this filter for Previous Month

<filter string="Prev Month" name="prev_month" domain="[('date_order','&gt;=',(context_today()-relativedelta(months=1)).strftime('%Y-%m-01')),('date_order','&lt;',time.strftime('%Y-%m-01'))]"/>

What I would prefer is if it also could filter like this:

date_order in between 11-12 months ago.

And also everything >12 months ago.

any ideas?

Avatar
Discard
Author Best Answer

We solved it this way:


<filter string="5-6 months" domain="[('date_order', '&gt;=', ((context_today()+relativedelta(months=-6, days=1, weekday=0)).strftime('%Y-%m-%d'))),('date_order', '&lt;=', ((context_today()+relativedelta(months=-5,weekday=6)).strftime('%Y-%m-%d')))]"/>
                    <filter string="7-11 months" domain="[('date_order', '&gt;=', ((context_today()+relativedelta(months=-11, weeks=-1, days=1, weekday=0)).strftime('%Y-%m-%d'))),('date_order', '&lt;=', ((context_today()+relativedelta(months=-7,weekday=6)).strftime('%Y-%m-%d')))]"/>
                    <filter string="11-12 months" domain="[('date_order', '&gt;=', ((context_today()+relativedelta(years=-1, weeks=-1, days=1, weekday=0)).strftime('%Y-%m-%d'))),('date_order', '&lt;=', ((context_today()+relativedelta(months=-11,weekday=6)).strftime('%Y-%m-%d')))]"/>
                    <filter string="12 months+" domain="[('date_order', '&gt;=', ((context_today()+relativedelta(years=-30, days=1, weekday=0)).strftime('%Y-%m-%d'))),('date_order', '&lt;=', ((context_today()+relativedelta(years=-1, weeks=-1, weekday=6)).strftime('%Y-%m-%d')))]"/>
Avatar
Discard
Related Posts Replies Views Activity
0
Mar 15
4235
1
Oct 22
3155
0
Jun 21
1802
1
Jan 20
9455
7
Mar 17
12549