Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata

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
Abbandona
Autore

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

Autore

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

Post correlati Risposte Visualizzazioni Attività
1
dic 20
21023
0
gen 18
4528
1
dic 16
17172
0
mag 16
3262
2
gen 23
3423