Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ

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.

Ảnh đại diện
Huỷ bỏ
Tác giả

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...

Tác giả

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'))]"/>

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 12 20
21203
0
thg 1 18
4645
1
thg 12 16
17361
0
thg 5 16
3358
2
thg 1 23
3581