如何在搜索视图中应用过滤器,基于用户 - OpenERP 7.0?

时间:2014-05-20 16:14:55

标签: filter treeview openerp searchview openerp-7

我正在尝试在树视图中应用一些过滤器。一切都很顺利,直到我尝试应用基于user.id的过滤器 我的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>

除了3基于user.id(例如)

之外,所有过滤器和组都正常工作

我在不同的浏览器上得到了不同的js错误:

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

我尝试添加context =“{'group_by':'requestor'}”,以防万一,但我得到了同样的错误!我在这里缺少什么想法?

提前致谢。

1 个答案:

答案 0 :(得分:2)

我想我已经忘了OpenERP。我格式化了过滤器域,我应该使用uid而不是user.id。这样,过滤器应为<filter icon="terp-mail-message-new" string="My Requests" name="my_requests_filter" domain="[('requestor','='uid)]" />

而且,BTW,如果想要在树视图上将过滤器设置为默认值,则必须在操作定义中添加以下代码:

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