Skip to Content
Menu
This question has been flagged
1 Reply
4771 Views

Dear friends, I am tryng to set a date filter for yesterday under develop mode.


I edit search view and find today filter as default filter. It is like this 


 <filter string="Today" domain="[('date_order', '&gt;=', datetime.datetime.now().strftime('%Y-%m-%d 00:00:00')),('date_order', '&lt;=',datetime.datetime.now().strftime('%Y-%m-%d 23:23:59'))]"/>

 

I want to add yesterday filter, i thought just minus the current date. but i came with error. Anybody knows how to do?

Thanks.

<filter string="Yesterday" domain="[('date_order', '&gt;=', (datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')),('date_order', '&lt;=',(datetime.datetime.now()-datetime.timedelta(days=1)).strftime('%Y-%m-%d 23:23:59'))]"/>


error:
Error: Failed to evaluate search criterions: 
{"code":400,"message":"Evaluation Error","data":{"type":"local_exception","debug":"Local evaluation failure\nTypeError: unsupported operand type(s) for +: 'datetime' and 'timedelta'\n\n{\"domains\":[[[\"state\",\"in\",[\"draft\",\"sent\",\"cancel\"]]],\"[('date_order', '>=', (datetime.datetime.now()+datetime.timedelta(days=-1)).strftime('%Y-%m-%d 00:00:00')),('date_order', '<=',datetime.datetime.now().strftime('%Y-%m-%d 23:23:59'))]\"],\"contexts\":[{\"lang\":\"en_US\",\"tz\":false,\"uid\":1,\"params\":{\"action\":290,\"page\":0,\"limit\":80,\"view_type\":\"list\",\"model\":\"sale.order\",\"_push_me\":false}},{}],\"group_by_seq\":[]}"}}
Avatar
Discard
Best Answer
<filter string="Yesterday" domain="[('date_order','&gt;=', ((context_today()-datetime.timedelta(days=1)).strftime('%Y-%m-%d 00:00:00'))), ('date_order','&lt;=', ((context_today()+datetime.timedelta(days=0)).strftime('%Y-%m-%d 00:00:00')))]"/>


Hope this one helps you.


Avatar
Discard
Related Posts Replies Views Activity
3
Apr 17
2250
1
Sep 16
56
0
Mar 15
3784
1
Jul 22
2127
9
Dec 23
36929