一、搜索
1、xml代码
<!--搜索和筛选-->
<record id="view_search_book_message" model="ir.ui.view">
<field name="name">book_message</field>
<field name="model">book_message</field>
<field name="arch" type="xml">
<search>
<!--搜索-->
<field name="bookwarehouse"/>
<field name="location"/>
</search>
</field>
</record>
在act_window下添加search_view_id,
<record id="action_book_message" model="ir.actions.act_window">
<field name="name">图书档案</field>
<field name="res_model">book_message</field>
<field name="search_view_id" ref="view_search_book_message"/>
<!-- 默认分组 -->
<!--<field name="context">{'search_default_inuse':True}</field> -->
<field name="context">{'search_default_group_by_classify':'1'}</field>
<field name="view_mode">tree,form,pivot,graph</field>
</record>
2、效果
二、筛选
1、效果
2、方法一:在py文件字段加search_able=True
classify = fields.Selection([('1', '语文'), ('2', '数学')], default='1', string='图书分类', search_able=True)
方法二:在py文件下添加方法
@api.model
def fields_get(self, allfields=None, attributes=None):
res = super().fields_get(allfields=allfields, attributes=attributes)
res['bookwarehouse']['string'] = '书库名称'
res['bookwarehouse']['searchable'] = True
return res
方法三:
<!--搜索和筛选-->
<record id="view_search_book_message" model="ir.ui.view">
<field name="name">book_message</field>
<field name="model">book_message</field>
<field name="arch" type="xml">
<search>
<!--搜索-->
<field name="bookwarehouse"/>
<field name="location"/>
<!--筛选-->
<filter name="classify" string="数学" domain="[('classify','=', '1')]"/>
<filter name="classify" string="语文" domain="[('classify','=', '2')]"/>
<!--分割线-->
<separator/>
<filter string="状态" name="status" domain="[('status', '=', '2')]" />
</search>
</field>
</record>
选择自己适用的方法即可
三、分组
1、xml文件代码
<!--搜索和筛选-->
<record id="view_search_book_message" model="ir.ui.view">
<field name="name">book_message</field>
<field name="model">book_message</field>
<field name="arch" type="xml">
<search>
<!--搜索-->
<field name="bookwarehouse"/>
<field name="location"/>
<!--分组-->
<group expand="1" string="Group By">
<filter string="classify" name="group_by_classify" context="{'group_by': 'classify'}"/>
</group>
</search>
</field>
</record>
2、在act_window添加context
<record id="action_book_message" model="ir.actions.act_window">
<field name="name">图书档案</field>
<field name="res_model">book_message</field>
<field name="search_view_id" ref="view_search_book_message"/>
<!-- 默认分组 -->
<!--<field name="context">{'search_default_inuse':True}</field> -->
<field name="context">{'search_default_group_by_classify':'1'}</field>
<field name="view_mode">tree,form,pivot,graph</field>
</record>
3、默认分组按照classify分组: