Search View Filters In Odoo
Hi All,
Today Filter
<filter icon="terp-go-month" string="Today " separator="1" domain="[('date','<=', (datetime.date.today()).strftime('%Y-%m-%d')),('date','>=',(datetime.date.today()).strftime('%Y-%m-%d'))]" help="Created today"/>
OR
<filter icon="terp-go-today" 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)))]" help="Orders processed Today or planned for Today"/>
This Year
<filter string="This Year" name="year" domain="[('date','<=', time.strftime('%%Y-12-31')),('date','>=',time.strftime('%%Y-01-01'))]"/>
Last Week
<filter 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')))]"/>
This Month
<filter icon="terp-go-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'))]" help="Current Month"/>
Current week
<filter icon="terp-go-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'))]"
help="Current Week"
context="{'group_by':'date_order'}"/>
Previous Month
<filter 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'))]"/>
<filter string="Immediate Expiry" name="od_imm" domain="[('expiry_date','>=', ((context_today()+datetime.timedelta(days=1)).strftime('%Y-%m-%d'))),('expiry_date','<=', ((context_today()+datetime.timedelta(days=45)).strftime('%Y-%m-%d')))]"/>
Yesterday
<filter 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
<filter 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')))]"/>
Filters for Datetime field
Today Filter
<filter icon="terp-go-month" string="Today " separator="1" domain="[('date','<=', (datetime.date.today()).strftime('%Y-%m-%d')),('date','>=',(datetime.date.today()).strftime('%Y-%m-%d'))]" help="Created today"/>
OR
<filter icon="terp-go-today" 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)))]" help="Orders processed Today or planned for Today"/>
This Year
<filter string="This Year" name="year" domain="[('date','<=', time.strftime('%%Y-12-31')),('date','>=',time.strftime('%%Y-01-01'))]"/>
Last Week
<filter 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')))]"/>
This Month
<filter icon="terp-go-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'))]" help="Current Month"/>
Current week
<filter icon="terp-go-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'))]"
help="Current Week"
context="{'group_by':'date_order'}"/>
Previous Month
<filter 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'))]"/>
Expiry checking
<filter string="Immediate Expiry" name="od_imm" domain="[('expiry_date','>=', ((context_today()+datetime.timedelta(days=1)).strftime('%Y-%m-%d'))),('expiry_date','<=', ((context_today()+datetime.timedelta(days=45)).strftime('%Y-%m-%d')))]"/>
Yesterday
<filter 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
<filter 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')))]"/>
Filters for Selection Field
Eg:<filter string="Quotations" name="draft" domain="[('state','in',('draft','sent'))]" help="Sales Order that haven't yet been confirmed"/>
Eg:<filter string="To Invoice" domain="[('state','=','manual')]" help="Sales Order ready to be invoiced"/>
Filters for Boolean Field
Eg:<filter icon="terp-gtk-jump-to-ltr" string="To Review" domain="[('to_check','=',True)]" help="Journal Entries to Review"/>
Filters for Many2one Field
<filter domain="[('user_id','=',uid)]" help="My Invoices" string="My Invoices"/>
for many2one field we are usually adding group by instead of filters.
you can add filters for many2one field by hard coding ids
Eg:-<filter domain="[('partner_id','in',(1,2,9,8,22)]" help="Selected" string="Special Partners"/>
Eg:-<filter domain="[('partner_id','=',1]" help="Selected" string="My Order"/>
<filter string="Last Week" name="Last Week" separator="1"
<filter string="Tomorrow" name="Tomorrow" separator="1"
<filter string="Immediate Expiry" name="Immediate Expiry" separator="1"
Filters for Date Field
This week
<filter 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')))]"
help="This Week"/>
Last Week
<filter 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')))]"
help="This Week"/>
yesterday
<filter string="Yesterday" name="Yesterday" separator="1"
domain="[('date_from','>=', ((context_today()+datetime.timedelta(days=-1)).strftime('%Y-%m-%d'))), ('date_from','<=', ((context_today()+datetime.timedelta(days=-1)).strftime('%Y-%m-%d')))]"
help="Yesterday"/>
Today
<filter string="Today" name="Today" separator="1"
domain="[('date_from','>=', ((context_today()+datetime.timedelta(days=0)).strftime('%Y-%m-%d'))), ('date_from','<=', ((context_today()+datetime.timedelta(days=0)).strftime('%Y-%m-%d')))]"
help="Today"/>
Tomorrow
<filter string="Tomorrow" name="Tomorrow" separator="1"
domain="[('date_from','>=', ((context_today()+datetime.timedelta(days=1)).strftime('%Y-%m-%d'))), ('date_from','<=', ((context_today()+datetime.timedelta(days=1)).strftime('%Y-%m-%d')))]"
help="Tomorrow"/>
Expiry
<filter string="Immediate Expiry" name="Immediate Expiry" separator="1"
domain="[('date_from','>=', ((context_today()+datetime.timedelta(days=0)).strftime('%Y-%m-%d'))), ('date_from','<=', ((context_today()+datetime.timedelta(days=45)).strftime('%Y-%m-%d')))]"
help="Immediate Expiry"/>
Last Month
<filter icon="terp-go-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'))]"
help="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'))]"
help="last month"/>
Current Month
<filter string="Current Month" name="current_month" domain="[('date_from','<',(context_today()+relativedelta(months=1)).strftime('%Y-%m-01')), ('date_from','>=',time.strftime('%Y-%m-01'))]"/>
Last Year
<filter icon="terp-go-month" string="Last Year"
domain="[('date', '>=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')),('date','<=',time.strftime('%Y-01-01'))]" help="last year"/>
domain="[('date', '>=' ,(context_today()-relativedelta(years=1)).strftime('%Y-01-01')),('date','<=',time.strftime('%Y-01-01'))]" help="last year"/>
This Year
<filter icon="terp-go-year" string="Year"
domain="[('date_from','<=', time.strftime('%Y-%m-%d')),('date_from','>=',time.strftime('%Y-01-01'))]"
help="Current Year"/>
domain="[('date_from','<=', time.strftime('%Y-%m-%d')),('date_from','>=',time.strftime('%Y-01-01'))]"
help="Current Year"/>
Group By
For adding a group by just define the field and add a filter inside the group tag.
Eg:-am adding a group by for partner field
<?xml version="1.0"?>
<search string="Search Sales Order">
<field name="partner_id"/>
<group expand="0" string="Group By">
<filter string="Customer" domain="[]" context="{'group_by':'partner_id'}"/>
</group>
</search>
<search string="Search Sales Order">
<field name="partner_id"/>
<group expand="0" string="Group By">
<filter string="Customer" domain="[]" context="{'group_by':'partner_id'}"/>
</group>
</search>
Tambahkan Komentar