<button name="button_scrap" type="object" string="Scrap" />
def button_scrap(self):
self.ensure_one()
view = self.env.ref('stock.stock_scrap_form_view2')
products = self.env['product.product']
for move in self.move_lines:
if move.state not in ('draft', 'cancel') and move.product_id.type in ('product', 'consu'):
products |= move.product_id
return {
'name': _('Scrap'),
'view_type': 'form',
'view_mode': 'form',
'res_model': 'stock.scrap',
'view_id': view.id,
'views': [(view.id, 'form')],
'type': 'ir.actions.act_window',
'context': {'default_picking_id': self.id, 'product_ids': products.ids},
'target': 'new',
}
示例:


object 返回一个指定的视图 ,直接是返回一个json格式的action
参数如下:
type: 动作类型,默认为ir.actions.act_window
view_type: 跳转时打开的视图类型
view_mode: 列出允许使用的视图模式
context: 给目标视图传参数,如默认搜索之类的,如{‘search_default_group_assign’:1}
limit: 列表视图一页的记录数
target: 打开新视图的方式,current是在本视图打开,new是弹出一个窗口打开
auto_refresh:为1时在视图中添加一个刷新功能
auto_search:加载默认视图后,自动搜索
multi:视图中有个更多按钮,若multi设为True, 更多按钮显示在tree视图,否则显示在form视图
res_model:想打开视图的对应模块
res_id: 参数为id,加载指定id的视图,但只在view_type为form时生效,若没有这个参数则会新建一条记录
view_id: 参数是id,若一个模块有多于>1个视图时需要指定视图id,可根据视图名称去ir.ui.view模块搜索
views:是(view_id,view_type) 元组对列表,第一组是动作默认打开的视图
flags: 对视图面板进行一些设置,
- 如{‘form’: {‘action_buttons’: True, ‘options’: {‘mode’: ‘edit’}}}即对form视图进行一些设置,action_buttons为True时调出编辑保存按钮
- options’: {‘mode’: ‘edit’}时则打开时对默认状态为编辑状态
- 'flags': {'mode': 'readonly'},时则打开时对默认状态为只读状态
网友评论