我的对象中有一个日期字段,而数据字段则希望在group by中显示数据。我已经尝试使用likee这样的数据组。但它没有效果。
示例:
<filter icon="terp-go-year" string="Year"
domain="[('date_from','<=', time.strftime('%%Y-%%m-%%d')),('date_from','>=',time.strftime('%%Y-01-01'))]"
help="Current Year"/>
<filter icon="terp-go-month" string="Month"
name="month"
domain="[('date_from','<=',(datetime.date.today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),('date_from','>=',(datetime.date.today()-relativedelta(day=1)).strftime('%%Y-%%m-%%d'))]"
help="Current Month"/>
<filter icon="terp-go-week"
string="Week"
separator="1"
name="week"
domain="[('date_from','<=', (datetime.date.today() + relativedelta(weeks=0,day=7, weekday=-1)).strftime('%%Y-%%m-%%d')),('date_from','>=',(datetime.date.today() - relativedelta(weeks=1, weekday=0)).strftime('%%Y-%%m-%%d'))]"
help="Current Week"/>
它不适合我:(
答案 0 :(得分:1)
我做了一些小改动。
<filter icon="terp-go-year"
string="Year"
domain="[('date_from','<=', time.strftime('%%Y-%%m-%%d')),'date_from','>=',time.strftime('%%Y-01-01'))]"
help="Current Year"
context="{'group_by':'date_from'}"/>
<filter icon="terp-go-month"
string="Month"
name="month"
domain="[('date_from','<=',(context_today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),('date_from','>=',(context_today()-relativedelta(day=1)).strftime('%%Y-%%m-%%d'))]"
help="Current Month"
context="{'group_by':'date_from'}"/>
<filter icon="terp-go-week"
string="Week"
separator="1"
name="week"
domain="[('date_from','<=', (context_today() + relativedelta(weeks=0,day=7, weekday=-1)).strftime('%%Y-%%m-%%d')),('date_from','>=',(context_today() - relativedelta(weeks=1, weekday=0)).strftime('%%Y-%%m-%%d'))]"
help="Current Week"
context="{'group_by':'date_from'}"/>
我在每个过滤器中添加了context="{'group_by':'date_from'}"
,而datetime.date.today()
我将其替换为context_today()
。
现在它可以正常工作。