openerp学习笔记 搜索视图(自己创建的、自己的、本部门的、本部门及下属部门的、今日的、日期从,日期至、多条件模糊搜索、or、and)

自己创建的:

domain="[('create_uid','=',uid)]"

自己的:

domain="[('employee_id','=','#kl_user_emp#')]"

本部门的:

domain="[('department_id','=','#kl_user_dept#')]"

本部门及下属部门的:

domain="[('department_id','child_of','#kl_user_dept#')]"

今日的:

domain="[('date_from','<=',time.strftime('%%Y-%%m-%%d 23:59:59')),('date_from','>=',time.strftime('%%Y-%%m-%%d 00:00:00'))]"

日前从,日期至:

<field name="date_from" string="日期从" filter_domain="[('date_from','&gt;=',self)]"/>
<field name="date_from" string="日期至" filter_domain="[('date_from','&lt;=',self)]"/>

多条件模糊过滤:(可以实现按名称和拼音简码过滤的效果)

<field name="name" filter_domain="['|',('name','ilike',self),'|',('default_code','ilike',self),('variants','ilike',self)]"/>

注意:<separator/> 统一分组内的过滤条件为 or 关系,不同分组内的过滤条件为 and 关系

          搜索视图中引用的字段,必须在对应的 tree 视图中存在,可以不显示(invisible = "1"),计算字段、关联字段的值在对象中未保存时,默认不支持搜索(可以在后台编码支持搜索)

 代码示例:

 

 

    <record model="ir.ui.view" id="dispatch_sale_filter">
        <field name="name">dispatch.sale.filter</field>
        <field name="model">dispatch.sale</field>
        <field name="type">search</field>
        <field name="arch" type="xml">
            <search string="销售单">
                <field name="name"/>
                <field name="customer"/>
                <field name="product"/>
                <field name="month"/>
                <field name="date"/>
                <filter name="my_filter"
                        string="自己创建的"
                        icon="terp-personal"
                        domain="[('create_uid','=',uid)]"/>
                <field name="create_uid"/>
                <filter name="self_filter"
                        string="自己的"
                        icon="terp-personal"
                        domain="[('employee_id','=','#kl_user_emp#')]"/>
                <field name="employee_id"/>
                <filter name="department_filter"
                        string="本部门的"
                        icon="terp-personal"
                        domain="[('department_id','=','#kl_user_dept#')]"/>
                <field name="department_id"/>
                <separator/>
                <filter icon="terp-check" domain="[('state','=','draft')]" string="草稿" name="draft"/>
                <filter icon="terp-check" domain="[('state','=','confirmed')]" string="已确认" name="confirm"/>
                <group expand="0" string="分组">
                    <filter string="按月" icon="terp-personal" domain="[]" context="{'group_by':'month'}"/>
                    <filter string="员工" icon="terp-personal" domain="[]" context="{'group_by':'employee_id'}"/>
                    <filter string="部门" icon="terp-personal+" domain="[]" context="{'group_by':'department_id'}"/>
                    <filter string="客户" icon="terp-personal" domain="[]" context="{'group_by':'customer'}"/>
                    <filter string="产品" icon="terp-personal+" domain="[]" context="{'group_by':'product'}"/>
                    <filter string="状态" icon="terp-stock_effects-object-colorize" domain="[]" context="{'group_by':'state'}"/>
                </group>
            </search>
        </field>
    </record>

    <record model="ir.actions.act_window" id="action_dispatch_sale_mgmt">
        <field name="name">销售单管理</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">dispatch.sale</field>
        <field name="view_type">form</field>
        <field name="view_mode">tree,form</field>
        <field name="view_id" ref="dispatch_sale_tree"/>
        <field name="search_view_id" ref="dispatch_sale_filter"/>
        <field name="context">{'search_default_draft':1}</field> <!--默认查询草稿状态的-->
    </record>

        <!-- actions -->
        <record id="action_kl_qingjd_my" model="ir.actions.act_window">
            <field name="name">我的请假单</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">kl.qingjd</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form,calendar</field>
            <field name="view_id" ref="kl_qingjd_tree"/>
            <field name="domain">[('create_uid','=',uid)]</field> <!-- 查看自己创建的请假单 -->
            <field name="context">{'btn_validate_invisible':False}</field>
            <field name="search_view_id" ref="kl_qingjd_filter"/>
        </record>

        <!-- actions -->
        <record id="action_kl_qingjd_validate" model="ir.actions.act_window">
            <field name="name">请假单审批</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">kl.qingjd</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="kl_qingjd_tree"/>
            <field name="domain">[('state','!=','draft'),('employee_id.parent_id.user_id','=',uid)]</field> <!--查询非草稿状态的,自己直接下属的请假单-->
            <field name="context">{'search_default_confirm':1, 'btn_validate_invisible':False}</field> <!--默认查询待审批的-->
            <field name="search_view_id" ref="kl_qingjd_filter"/>
        </record>

        <!-- actions -->
        <record id="action_kl_qingjd_query" model="ir.actions.act_window">
            <field name="name">请假单查询</field>
            <field name="type">ir.actions.act_window</field>
            <field name="res_model">kl.qingjd</field>
            <field name="view_type">form</field>
            <field name="view_mode">tree,form</field>
            <field name="view_id" ref="kl_qingjd_tree"/>
            <field name="domain">[('state','!=','draft'),('department_id','child_of','#kl_user_dept#')]</field><!--查询非草稿状态的,自己部门及下属部门的请假单-->
            <field name="context">{'search_default_department_filter':1, 'btn_validate_invisible':False}</field> <!--默认查询本部门的-->
            <field name="search_view_id" ref="kl_qingjd_filter"/>
        </record>

今日的:

<filter icon="terp-go-today" string="今日的" domain="[('date_from','&lt;=',time.strftime('%%Y-%%m-%%d 23:59:59')),('date_from','&gt;=',time.strftime('%%Y-%%m-%%d 00:00:00'))]"/>


日前从,日期至:

<field name="date_from" string="日期从" filter_domain="[('date_from','&gt;=',self)]"/>
<field name="date_from" string="日期至" filter_domain="[('date_from','&lt;=',self)]"/>

 
多条件模糊过滤:(可以实现按名称和拼音简码过滤的效果)

<field name="name" filter_domain="['|',('name','ilike',self),'|',('default_code','ilike',self),('variants','ilike',self)]"/>

posted @ 2013-06-27 17:50  cnshen  阅读(291)  评论(0编辑  收藏  举报