我想从按钮传递一个默认域以应用于目标操作。
像这样:
<!-- action -->
<act_window id="action_target"
name="Project Categories"
res_model="addon.model"
view_mode="kanban,tree,form"/>
<!-- button -->
<button class="btn btn-primary"
type="action"
name="%(action_target)d"
domain="[('field_x', '=', self.id)]">
Do Something
</button>
我现在的做法是触发一个打开新操作窗口的函数:
@api.multi
def action_target(self):
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'src_model': self._name,
'res_model': 'addon.model',
'view_mode': 'kanban,tree,form',
'domain': [('field_x', '=', self.id)],
'target': 'main',
}
我这样做的方式带来的不良行为是,它不会像操作按钮那样保留到上一个窗口的路径:
我希望它保持这样:
如何实现?
请您参考如下方法:
我不太确定你到底想做什么,但我们开始吧:
如果您想打开另一个 View 显示所有记录,其中 field_x = self.id
在操作的上下文中使用 'search_default_field_x': self.id。这应该会打开带有搜索集的 View ,查找 field_x 等于 self.id 的每条记录。您可能需要定义一个搜索 View ,该 View 能够在 field_x 上进行搜索以使其工作(如果字段不在 View 中,则 default 将不会填充该字段)。
我认为这回答了您标题中的问题和问题的第一部分。
如果您不想破坏面包屑:
Window Actions (ir.actions.act_window)
target (optional) whether the views should be open in the main content area (current), in full screen mode (fullscreen) or in a dialog/popup (new). Use main instead of current to clear the breadcrumbs. Defaults to current.
因此,请尝试使用 current 而不是 new,它应该可以满足您的需求。至少,它适用于我为公司编写的一些代码,但这是适用于 odoo 8 的。由于这是默认设置,这就是它适用于您的第一个代码段的原因。
