Search code examples
filtertreeviewodoosearchviewopenerp-7

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


I am trying to apply some filters in my tree view. And all was going fine until I tried to apply filters based on user.id My XML code looks like this:

<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. )

I get diffent js 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?

Thanks in advance.


Solution

  • I guess I'm loosing my mind with OpenERP. I was formatting badly the filter domain, I should use uid instead of user.id. This way, filters should be <filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','='uid)]" />

    And, BTW, if one wants to set a filter as a default on tree view, it has to add the following code in the 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>