Hello world. You know this is for me to refresh my brain at work. Today i just got task, very simple but sometimes we need to create with similar case that i have. So i just want to show or calling wizard, but its not from xml code but on the python code. On the previous post here, i just show wizard on the xml code, but now i try to show you different way its from python code. Lets do it.
So as you know wizard is model, but they have type TransientModel, it means they just save in temporary memory not to primary memory (database). Ya i just want you to know it, its first principle that i don't know before my friend told me. Lol.
This is my function to call wizard :
@api.multi def call_wizard(self): print "call wizard fucntion" wizard_form = self.env.ref('custom_wizard.cutom_wizard_view', False) view_id = self.env['dedy.yuristiawan.wizard'] vals = { 'name' : 'this is for set name', } new = view_id.create(vals) return { 'name' : _('Hi I am wizard, I am from python code'), 'type' : 'ir.actions.act_window', 'res_model' : 'dedy.yuristiawan.wizard', 'res_id' : new.id, 'view_id' : wizard_form.id, 'view_type' : 'form', 'view_mode' : 'form', 'target' : 'new' }
As you can see, on the function i can get conclusion like this :
1. Declaration your wizard, like where is the wizard position. like this one :
wizard_form = self.env.ref('custom_wizard.cutom_wizard_view', False)
I just declaration my module custom_wizard and the template id cutom_wizard_view and then i put to variable wizard_form .
2. Create record to get id wizard. like this one :
view_id = self.env['dedy.yuristiawan.wizard']
vals = { 'name' : 'this is for set name', } new = view_id.create(vals)
in this code, i just call model and then i do create one record, set name (cause in my wizard model i just have one field is name ). And then i put to variable new . This variable is for get id, i can call with new.id .
3. Return Your function, to call wizard. Use this code :
return { 'name' : _('Hi I am wizard, I am from python code'), 'type' : 'ir.actions.act_window', 'res_model' : 'dedy.yuristiawan.wizard', 'res_id' : new.id, 'view_id' : wizard_form.id, 'view_type' : 'form', 'view_mode' : 'form', 'target' : 'new' }
name is for title wizard,
type for call action window,
res_model is for set our wizard model,
res_id is id record that we create before.
view_id is view that we create before,
view_type and view_mode is to set from for wizard,
and the last is target new for create new action.
Just it, you can read first, if you still confuse about my code you can fill comment bellow. I hope this code can help you little bit.


















