Odoo 搜索视图详解及代码示例

本文主要介绍了Odoo 搜索视图的开发方法并提供代码示例

搜索视图
search的可以设置一个filter_domain属性用来覆盖原field的匹配方法,其中的self代表用户的输入值。field字段用来定义给出过滤选项。另外可以用filter预定义一些搜索条件的快捷方式。group用来分组。

<search string="Ideas">
<field name="name"/>
<field name="description" string="Name and description"
filter_domain="['|', ('name', 'ilike', self), ('description', 'ilike', self)]"/>
<field name="inventor_id"/>
<field name="country_id" widget="selection"/>

<filter name="my_ideas" string="My Ideas"
domain="[('inventor_id', '=', uid)]"/>
<group string="Group By">
<filter name="group_by_inventor" string="Inventor"
context="{'group_by': 'inventor_id'}"/>
</group>
</search>

在action里通过search_view_id指定搜索视图

使用search_default指定默认筛选条件
在action中还能通过在context里指定默认开启的搜索条件,使用{'search_default_field_name':1}

field_name为搜索视图中filter对应的名称,1表示真值。

如odoo原生的app界面过滤应用使用了如下代码

search view里定义filter

action里调用

{'search_default_app':1}
效果

参考文章: https://www.erpdaxue.cn/odoo/odoo教程/odoo-搜索视图详解/

 

posted @ 2020-03-15 18:01  odoo开发者  阅读(1467)  评论(0编辑  收藏  举报