跳至内容
菜单
此问题已终结

I'm trying to create a filter which filters date records only from the current week (Monday - Sunday)

Here's the domain:

[
('date', '>=', datetime.datetime.now().date() - relativedelta(days=today.weekday()).strftime('%Y-%m-%d')),
('date', '<', datetime.datetime.now().date() + relativedelta(days=6-today.weekday()).strftime('%Y-%m-%d'))
]


My code runs, but when I click on the filter I get the following error:

Uncaught Promise > Failed to evaluate the domain ["&", ("user_id", "=", 2), "&", ("date", ">=", datetime.datetime.now().date() - relativedelta(days = today.weekday()).strftime("%Y-%m-%d")), ("date", "


I've tried search online for 'fnValue is not a function', but I get 0 results...

I've also tried using context_today() instead of datetime.datetime.now().date(), but it returns the same error...


Any idea what this error could mean?

Any idea how to approach the idea for this filter?


The Odoo source code already contains a similar filter, namely:

[
('create_date', '>=', (datetime.datetime.combine(context_today() + relativedelta(weeks=-1,days=1,weekday=0), datetime.time(0,0,0)).to_utc()).strftime('%Y-%m-%d %H:%M:%S')),
('create_date', '<', (datetime.datetime.combine(context_today() + relativedelta(days=1,weekday=0), datetime.time(0,0,0)).to_utc()).strftime('%Y-%m-%d %H:%M:%S'))
]


But this uses create_date and I want to use my own field 'date', which doesn't contain any time data.

形象
丢弃
编写者

Nevermind, I created a filter which works the way I want it to:
<filter string="This week" name="this_week" domain="[('date', '>=', (context_today() + relativedelta(weeks=-1,days=1,weekday=0)).strftime('%Y-%m-%d')), ('date', '&lt;', (context_today() + relativedelta(days=1,weekday=0)).strftime('%Y-%m-%d'))]"/>

I still wonder what caused the 'fnValue is not a function' error though...

编写者

Updated my filter once again and also added a filter for last week:

<filter string="This week" name="this_week" domain="[('date', '&gt;=', (context_today() + relativedelta(weeks=-1, days=1, weekday=0)).strftime('%Y-%m-%d')), ('date', '&lt;=', (context_today() + relativedelta(days=-1, weekday=6)).strftime('%Y-%m-%d'))]"/>

<filter string="Last week" name="last_week" domain="[('date', '&gt;=', (context_today() + relativedelta(weeks=-2, days=1, weekday=0)).strftime('%Y-%m-%d')), ('date', '&lt;=', (context_today() + relativedelta(weeks=-1, days=-1, weekday=6)).strftime('%Y-%m-%d'))]"/>

相关帖文 回复 查看 活动
1
12月 20
21090
0
1月 18
4564
1
12月 16
17213
0
5月 16
3296
2
1月 23
3475