Search Here

Odoo Search Filters on Date and Datetime Field

 In this article you will learn how to create search filters in Odoo by using date and datetime field. I will also show you how to use operators less or equal than or greater or equal than parameters in XML search view.

How to filter by Date field in Odoo

How to filter by Date field in Odoo


Filter Example
Today string="Today " separator="1" domain="[('date','<=', (datetime.date.today()).strftime('%Y-%m-%d')),('date','>=',(datetime.date.today()).strftime('%Y-%m-%d'))]"

OR

string="Today" domain="[('date','<=', datetime.datetime.combine(context_today(), datetime.time(23,59,59))), ('date','>=', datetime.datetime.combine(context_today(), datetime.time(0,0,0)))]"
Yesterday string="Yesterday" domain="[('date_order','>=', ((context_today()-datetime.timedelta(days=1)).strftime('%Y-%m-%d 00:00:00'))), ('date_order','<=', ((context_today()+datetime.timedelta(days=0)).strftime('%Y-%m-%d 00:00:00')))]"
Tomorrow string="Tomorrow" domain="[('date_order','>=', ((context_today()+datetime.timedelta(days=0)).strftime('%Y-%m-%d 23:59:59'))), ('date_order','<=', ((context_today()+datetime.timedelta(days=1)).strftime('%Y-%m-%d 23:59:59')))]"
Current Year string="Current Year" name="year" domain="[('date','<=', time.strftime('%%Y-12-31')),('date','>=',time.strftime('%%Y-01-01'))]"
Last Year string="Last Year" domain="[('date', '>=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')),('date','<=',time.strftime('%Y-01-01'))]"
Current Month string="Month" name="month" domain="[('date_order','<=',(datetime.date.today()+relativedelta(day=31)).strftime('%Y-%m-%d')),('date_order','>=',(datetime.date.today()-relativedelta(day=1)).strftime('%Y-%m-%d'))]"
Previous Month string="Prev Month" name="prev_month" domain="[('date_order','>=',(context_today()-relativedelta(months=1)).strftime('%Y-%m-01')),('date_order','<',time.strftime('%Y-%m-01'))]"
Last Month string="Last Month" domain="[('date_from','<=', (context_today()-relativedelta(day=31, months=1)).strftime('%Y-%m-%d')), ('date_from','>=',(context_today()-relativedelta(day=1,months=1)).strftime('%Y-%m-%d'))]"
Current Week string="Current Week" separator="1" name="week" domain="[('date_order','<=', (context_today() + relativedelta(weeks=0,day=7, weekday=-1)).strftime('%Y-%m-%d')),('date_order','>=',(context_today() - relativedelta(weeks=1, weekday=0)).strftime('%Y-%m-%d'))]"
This Week string="This Week" name="This Week" separator="1" domain="[('date_from','>=', ((context_today()).strftime('%Y-%m-%d'))), ('date_from','<=', ((context_today()+datetime.timedelta(days=7)).strftime('%Y-%m-%d')))]"
Last Week string="Last week" domain="[('date_order', '>=', ((context_today()+relativedelta(weeks=-2,days=1, weekday=0)).strftime('%Y-%m-%d'))),('date_order', '<=', ((context_today()+relativedelta(weeks=-1,weekday=6)).strftime('%Y-%m-%d')))]"

OR

string="Last Week" name="Last Week" separator="1" domain="[('date_from','>=', ((context_today()+datetime.timedelta(days=-7)).strftime('%Y-%m-%d'))), ('date_from','<=', ((context_today()).strftime('%Y-%m-%d')))]"

Post a Comment

1 Comments

  1. why you are using double parenthesis there

    (('user_id.employee_id.parent_id.user_id', '=' , user.id)

    ReplyDelete