3

我的对象中有一个日期字段,并且从数据字段中希望按分组显示数据。我已经尝试过使用likee这个数据组。但它没有效果。

例子:

<filter icon="terp-go-year" string="Year"
                            domain="[('date_from','&lt;=', time.strftime('%%Y-%%m-%%d')),('date_from','&gt;=',time.strftime('%%Y-01-01'))]"
                            help="Current Year"/>
                    <filter icon="terp-go-month" string="Month"
                            name="month"
                            domain="[('date_from','&lt;=',(datetime.date.today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),('date_from','&gt;=',(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','&lt;=', (datetime.date.today() + relativedelta(weeks=0,day=7, weekday=-1)).strftime('%%Y-%%m-%%d')),('date_from','&gt;=',(datetime.date.today() - relativedelta(weeks=1, weekday=0)).strftime('%%Y-%%m-%%d'))]"
                            help="Current Week"/>

它不适合我:(

4

1 回答 1

1

我做了一些小改动。

<filter icon="terp-go-year" 
        string="Year"
        domain="[('date_from','&lt;=', time.strftime('%%Y-%%m-%%d')),'date_from','&gt;=',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','&lt;=',(context_today()+relativedelta(day=31)).strftime('%%Y-%%m-%%d')),('date_from','&gt;=',(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','&lt;=', (context_today() + relativedelta(weeks=0,day=7, weekday=-1)).strftime('%%Y-%%m-%%d')),('date_from','&gt;=',(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().

现在它将正常工作。

于 2013-05-08T13:30:20.907 回答