Odoo Help


How to apply filter in search view, based on user?

Luis Filipe Castanheira
on 5/20/14, 11:25 AM 3,666 views

I am trying to apply some filters in my tree view. I have these this XML:

   <record model="ir.ui.view" id="view_generic_request_search">
            <field name="name">generic_request.search</field>
            <field name="model">generic.request</field>
            <field name="arch" type="xml">
                <search string="Search Request">
                    <filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','=',user.id)]"}"/>
                    <filter icon="terp-mail-message-new" string="Requests I'm responsible" name="request_im_responsible_filter" domain="[('responsible_name','=',user.id)]" />
                    <filter icon="terp-mail-message-new" string="Requests I own" name="requests_i_own_filter" domain="[('owner','=',user.id)]" />
                    <separator />
                    <filter icon="terp-mail-message-new" string="Denied Requests" name="denied_requests_filter" domain="[('state','=','denied')]"/>
                    <filter icon="terp-mail-message-new" string="Authorized Requests" name="authorized_requests_filter" domain="[('state','=','authorized')]"/>
                    <filter icon="terp-mail-message-new" string="Confirmed Requests" name="confirmed_requests_filter" domain="[('state','=','confirmed')]"/>
                    <group expand="0" string="Group By...">
                        <filter string="Requested by" domain="[]" context="{'group_by' : 'requestor'}" />
                        <filter string="Responsible person" domain="[]" context="{'group_by' : 'responsible_name'}" />
                        <filter string="Status" domain="[]" context="{'group_by': 'state'}"/>

All filters and groups by are working fine, except the 3 based on user.id (ex. <filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','=',user.id)]"}"/> )

I get diffent error, on different browsers:

Chrome & IE
Uncaught TypeError: Cannot read property 'length' of undefined
TypeError: results.group_by is undefined

I tryed to add  context="{'group_by' : 'requestor'}", just in case, but I get the same error! Any ideia of what I'm missing here?


I was approaching it badly, the correct filter to apply is "uid" and not "user.id". So instead I have to put

<filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','=',uid)]"}"/>

BTW, just to add some more info, if you want to set a filter as default on your view, you have to add a context on your action definition:

        <record model="ir.actions.act_window" id="action_generic_request">
                    <field name="name">Generic Request</field>
                    <field name="res_model">generic.request</field>
                    <field name="view_type">form</field>
                    <field name="context">{"search_default_my_requests_filter":1}</field>
                    <field name="view_mode">tree,form</field>

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 5/20/14, 11:25 AM
Seen: 3666 times
Last updated: 3/16/15, 8:10 AM