我需要为我的模块的 TreeView 添加一个默认过滤器。
我在 openerp 中看到了一些代码示例,比如这个:
<filter
string="Partner"
icon="terp-partner"
domain="[]"
context="{'group_by':'partner_id'}"
/>
以purchase模块中的这个为例,按partner_id分组。
现在,我有一个自定义模块,当您单击它的菜单时,我需要有一个“默认”过滤器。
并且此过滤器必须显示所有未“过期”的记录,或者在我浏览模块中的记录时尚未超过实际日期的记录。
我的自定义模块中有这个字段:
'Fecha_de_Vence': fields.date(
'Fecha de Vencimiento',
required=True,
select=True,
),
这是我需要用作此模块中所有记录的过滤器的字段。
现在,在“高级搜索”中,我可以输入例如 Fecha de Vencimiento 不超过 实际日期,嗯,我需要将其作为 '默认过滤器。
谁能阐明如何在 openerp 的 xml View 中默认获取它?
请您参考如下方法:
您需要一个搜索 View ,以及 act_window 中的上下文条目:
<record id="search_xxx_filter" model="ir.ui.view">
<field name="name">module.class.select</field>
<field name="model">module.class</field>
<field name="arch" type="xml">
<search string="Search xxx">
<field name="Fecha_de_Vence" string="Fecha de Vencimiento" filter_domain="[(1,'=',1)]"/>
<separator/>
<filter string="Fecha de Vencimiento" name="type_date" domain="[(1,'=',1)]" help="..."/>
<separator/>
<group expand="0" string="Group By...">
<filter string="Assigned to" domain="[]" context="{'group_by' : 'user_id'}" />
<filter string="Status" domain="[]" context="{'group_by': 'state'}"/>
<filter string="Priority" domain="[]" context="{'group_by': 'priority'}"/>
</group>
</search>
</field>
</record>
<record id="module_class_act" model="ir.actions.act_window">
<field name="name">xxx</field>
<field name="res_model">module.class</field>
<field name="view_type">form</field>
<field name="context">{"search_default_type_date":1}</field>
<field name="view_id" ref="module_class_tree-view"/>
</record>
我保留了组条目,以便您可以看到它们的外观,但您需要删除它们或调整它们以使其与您的数据匹配。此外,单词 module 和 class 应该替换为您的数据。
