Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1962 Переглядів

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

Related Posts Відповіді Переглядів Дія
1
груд. 20
20518
0
січ. 18
4234
1
груд. 16
16823
0
трав. 16
2986
2
січ. 23
2928