OpenERP(odoo)开发实例之搜索过滤:检索过去3个月的数据 
解决这个问题的重点在于 relativedelta 的应用
 
示例代码如下:
 
 
1:  <!-- filter: last three months -->
2:  <filter icon="terp-personal" name="last_three_month"
3:          string="Last 3 Months"
4:          domain="[('date','&lt;=',time.strftime('%%d/%%m/%%Y')),
5:                   ('date','&gt;=',
6:                    ((context_today() -
7:                     relativedelta(months=3)).strftime('%%d/%%m/%%Y')))
8:                  ]"/>
 
解释:
 
第4行: time.strftime('%%d/%%m/%%Y') 返回的是当前日期; &lt;= 是小于号, 在 XML 中只能这样表示. 这一行表示: “在今天之前”.
第5, 6, 7行: context_today() 是 OpenERP 中另外一种返回当前日期的方式, 它减去relativedelta(months=3) 就是三个月前. 这三行表示: “大于三个月前”, 其中 &gt;= 是 XML 中的大于号.
合起来表示”三个月前到今天”, 即”过去三个月”