我使用"ir.actions.server"
添加了一个基于python代码的动态过滤器,您可以在项目模块grep --include '*.xml' -insr 'ir.actions.server'
中找到如何使用它的很好的示例,结果将是:{{ 1}}
我添加了一个python函数,该函数将根据某些条件返回过滤的记录。
看到我的XML声明:
views/project_views.xml:295: <record id="activate_sample_project" model="ir.actions.server">
my_python_function将返回过滤的记录,这里是我的python代码:
<record id="My_server_action" model="ir.actions.server">
<field name="name">Name of my server action</field>
<field name="model_id" ref="my_module.model_my_model"/>
<field name="code">
action = model.my_python_code()
</field>
</record>
但是如果我在默认搜索中使用另一个字段,例如:@api.multi
@api.model
def my_python_function(self):
context = self._context
current_user = context.get('uid')
if codition1 :
records = self.env['my.module'].search([
('fields1', '=', val1)
])
return {
'type': 'ir.actions.act_window',
'name': _('Customer name'),
'res_model': 'my.module',
'view_mode': 'tree,form,kanban,pivot,graph',
'context': {'search_default_id': records.ids}
}
else codition2 :
records = self.env['my.module'].search([
('fields2', '=', val2)
])
return {
'type': 'ir.actions.act_window',
'name': _('Customer name'),
'res_model': 'my.module',
'view_mode': 'tree,form,kanban,pivot,graph',
'context': {'search_default_id': records.ids}
}
,这将向我显示伙伴名称作为过滤器名称
任何帮助,谢谢前进