Search views
Search views are a new feature of OpenERP supported as of version 6.0 It creates a customized search panel, and is declared quite similarly to a form view, except that the view type and root element change to search instead of form.
下面是search视图中要用到的新的元素和特性列表。
Group tag
Unlike form group elements, search view groups support unlimited number of widget(fields or filters) in a row (no automatic line wrapping), and only use the following attributes:
expand: turns on the expander icon on the group (1 for expanded by default, 0 for collapsed)
string: label for the group
<group expand="1" string="Group By...">
<filter string="Users" icon="terp-project" domain="[]" context="{'group_by':'user_id'}"/>
<filter string="Project" icon="terp-project" domain="[]" context="{'group_by':'project_id'}"/>
<separator orientation="vertical"/>
<filter string="Deadline" icon="terp-project" domain="[]" context="{'group_by':'date_deadline'}"/>
</group>
以上的截图是个扩展group。
Filter tag
Filters在查找面板作为一个触发按钮方式显示,可以添加新的过滤元素在当前域或是查询视图的上下文。Filters可以作为一个字段子元素添加进去,来表示他们专门用于该字段(这种情况下button按钮会变小些)。
In the picture above the red area contains filters at the top of the form while the blue area highlights a field and it’s child filter.
<filter string="Current" domain="[('state','in',('open','draft'))]" help="Draft, Open and Pending Tasks" icon="terp-project"/>
<field name="project_id" select="1" widget="selection">
<filter domain="[('project_id.user_id','=',uid)]" help="My Projects" icon="terp-project"/>
</field>
Group By
<filter string="Project" icon="terp-project" domain="[]" context="{'group_by':'project_id'}"/>
以上的filters groups records都用相同的project_id值。groups懒加载,所以,inner records只在group扩展时加载。group header lines包含这个group中所有记录的共同值,并且所有数字型的字段一般先是在视图中,来代替值的和。
将指定的a list of fields的很多值分组来代替a single string是可能的。这种情况下,嵌套分组就会显示出来:
<filter string="Project" icon="terp-project" domain="[]" context="{'group_by': ['project_id', 'user_id'] }"/>
Actions for Search view
在声明一个search view后,它会被自动用在相同model的所有tree view中。如果一个model有几个search view,那它会使用拥有最高优先级的那个。另一个选择就是通过设置action中的search_view_id字段来明确选择想要使用的search view。
除了能够传递在action上下文中的默认表单值外,OpenERP 6.0现在支持通过上下文来传递search views的初始值。这个上下文keys需要匹配search_default_XXX格式。在search view中XXX是指
<record id="action_view_task" model="ir.actions.act_window">
<field name="name">Tasks</field>
<field name="res_model">project.task</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form,calendar,gantt,graph</field>
<field eval="False" name="filter"/>
<field name="view_id" ref="view_task_tree2"/>
<field name="context">{"search_default_current":1,"search_default_user_id":uid}</field>
<field name="search_view_id" ref="view_task_search_form"/>
</record>
Custom Filters
As of v6.0, all search views also features custom search filters, as show below. Users can define their own custom filters using any of the fields available on the current model, combining them with AND/OR operators. It is also possible to save any search context (the combination of all currently applied domain and context values) as a personal filter, which can be recalled at any time. Filters can also be turned into Shortcuts directly available in the User’s homepage.
在以上的截图中,我们过滤Partner用Salesman = Demo user 和Country = Belgium,我们将这个搜索标准作为快捷键或是保存为过滤器。
过滤器是用户特定的,可以通过在filters 下拉菜单中管理过滤器选项来进行修改。