Odoo Help

Welcome!

This community 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.

0

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

By
Luis Filipe Castanheira
on 5/20/14, 11:25 AM 1,750 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')]"/>
                    <separator/>
                    <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'}"/>
                    </group>
                </search>
            </field>
        </record>

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
http://myserveraddress:8069/web/webclient/js?db=may_9:3256
Firefox:
TypeError: results.group_by is undefined
http://myserveraddress:8069/web/webclient/js?db=may_9:3256

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?

1

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>
        </record>

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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