odoo10中,我要實現點擊一個按鈕,跳轉到一個視圖,需要按鈕對應一個方法,方法轉到視圖
# 跳轉到form @api.multi def action_account_invoice_view(self): """跳轉打開到當前報銷單關聯的付款單""" res_id = self.env['account.invoice'].search([ ('reimbursed_id', '=', self.id), ('type', '=', 'in_invoice'), ], order='id desc', limit=1) if not res_id: raise ValidationError(_('當前報銷單不存在付款單!')) return { 'type': 'ir.actions.act_window', 'name': '報銷賬單', 'res_model': 'account.invoice', 'views': [[False, "form"]], "res_id": res_id.id, "target": "current", } # 跳轉到列表 def account_move_view(self): """跳轉到關聯的報銷憑證""" return { 'name': "報銷憑證", 'view_type': 'form', 'view_mode': 'tree,form', 'res_model': 'account.move', 'domain': [('reimbursed_id', '=', self.id)], 'view_id': False, 'views': [ (self.env.ref('account.view_move_tree').id, 'tree'), (self.env.ref('account.view_move_form').id, 'form') ], 'type': 'ir.actions.act_window', }
odoo12中,可以通過action進行跳轉
例如:這是一個視圖
<record id="FrReimbursedForm" model="ir.ui.view"> ..................................... </record> <record id="ReimbursedAction" model="ir.actions.act_window"> <field name="name">報銷申請</field> <field name="type">ir.actions.act_window</field> <field name="res_model">fr.reimbursed</field> <field name="view_mode">tree,form</field> <field name="view_id" ref="FrReimbursedTree"/> </record>
現在我在別的視圖需要一個按鈕,跳轉到上面那個form視圖
<button name="%(ReimbursedAction)d" string="測試" type="action"/>
可以這樣定義,name跟%(aciton的id)d,type為action
在界面上,button對應的name就是action的數字id