Ir al contenido
Menú
Se marcó esta pregunta

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.

Avatar
Descartar
Autor

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

Autor

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

Publicaciones relacionadas Respuestas Vistas Actividad
1
dic 20
21026
0
ene 18
4531
1
dic 16
17175
0
may 16
3263
2
ene 23
3426