Search code examples
pythonpython-2.7odoo-8odoo

Odoo's date filter doesn't work as intended


In my view file, I have this filter

<filter name="today" string="Today" domain="[('date','&gt;=', datetime.datetime.combine(context_today(), datetime.time(0,0,0))), ('date', '&lt;=', datetime.datetime.combine(context_today(), datetime.time(23,59,59)))]" />

And I have set that filter to be enabled by default.

"search_default_today":1

In my database, my table has a date column which is a date type (not DateTime).

Ubuntu server's time, timezone and date settings already correct. Postgresql timezone set to local time.

But when I open the list view it shows yesterday's record. The filter works but not in the right way. When I discard the filter it shows all. When I apply the filter it shows yesterday's record.

What did I do wrong here?


Solution

  • Try this:

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

    OR:

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