The key to building this kind of filters is relativedelta , please read its manual for more details.
Here is an example:
1: <!-- filter: last three months --> 2: <filter icon="terp-personal" name="last_three_month" 3: string="Last 3 Months" 4: domain="[('date','<=',time.strftime('%%d/%%m/%%Y')), 5: ('date','>=', 6: ((context_today() - 7: relativedelta(months=3)).strftime('%%d/%%m/%%Y'))) 8: ]"/>
Explanation:
- Line #4:
time.strftime('%%d/%%m/%%Y')
returns the current date;<=
is the less-than sign in XML. This line means: “before today”. - Line #5,6,7:
context_today()
is another way to get the current date in OpenERP, subtract it withrelativedelta(months=3)
to get the date three months ago. So these three lines mean: “greater than three months ago”,>=
is the greater-than sign in XML. - All together: “from three months ago to today”, aka, “last three months”
Note:
- This link helped a lot
- Thanks to mrshelly
- Thanks to my colleague Tom
Happy Hacking!
Awesome post! Solved all my problem. Thanks a lot!