If you want to redirect to another object when an event occurs like click of a button, then you just need to return dictionary having the following syntax-
return {
‘name’:_(“Name of the form”),
‘view_mode’: ‘form’,
‘view_id’: False,
‘views’: [(resource_id,’form’)],
‘view_type’: ‘form’,
‘res_id’ : res_id, # id of the object to which to redirected
‘res_model’: ‘stock.picking’, # object name
‘type’: ‘ir.actions.act_window’,
‘target’: ‘new’, # if you want to open the form in new tab
}
Thank you for blog. I need to execute some python code on event click on button, but not redirect to another object. Is it possible and how?
Regards
For that you need to declare button as type=object. Like as follows-
And in .py file you need to define function create_moves
def create_moves(self, cr, uid, ids, context={}):
//Python code
Thanks for answer. I forgot to clearly describe problem. I have two buttons: one button which comes with instalation () and one created with your advices.
My problem is how integrate this two buttons into one with same functionlities: validate invoice and execute code in function create_moves.
Regards
Missing part between brackets is from file account_invoice_view.xml :
button name=”invoice_open” states=”draft,proforma2″ string=”Validate” icon=”gtk-go-forward”
button invoice_open is used as an event to move from one activity to another. If you want to execute any code, the best way is to call the function at the destination activity. Or you can describe the button as type=object and write the code there.
So, in your case, you need to inherit the view and just replace the button invoice_open with type=object. And define the function def invoice_open() in .py file.
but how to change focus???
On what event you want to change focus?
Hello Aasimansari, could you also explain how this can be done in Odoo 8? I would be very grateful!
Kind regards,
Daniel
Hello Daniel,
It’s the same way. Just search for “‘target’: ‘new'” in addons folder and you will get many such functions.
Thank you very much! I tried it but it did not work, until I used @api.multi instead of @api.one 🙂
http://stackoverflow.com/questions/37654086/how-to-redirect-to-another-form-view-in-python-code-odoo-8