Transferred from: http://www.chinamaker.net/
Search filtering for OpenERP (Odoo) Development examples: Retrieving data for the last 3 months
The key to solving this problem lies in the application of Relativedelta
The sample code is as follows:
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 4th:
time.strftime(‘%%d/%%m/%%Y‘)
returns the current date; <=
is a less than sign, which can only be represented in XML. This line says, "before today."
- 5th, 6, 7:
context_today()
It's another way to return the current date in OpenERP, minus relativedelta(months=3)
three months ago. These three lines indicate "greater than three months ago", where the >=
greater than sign is in XML.
- Together, "three months ago to today", or "last three months"
OpenERP (Odoo) Development Example search retrieves data for the last 3 months