OpenERP Module Development Wizard
Today we develop simple wizard call from menu item click. This wizard simply receive the value in text box, and using this value, will change the current user password.
Step 1: Create a folder (e.g. having name abc).
Step 2: Create a file abc_view.xml in abc folder.
Step 4: Write a wizard code in abc_view.xml like below (also create the __init__.py and __terp__.py files i am assuming you create both of these files correctly).
<wizard string="Change Password" model="res.users" name="abc.user.password" menu="False" id="wizard_abc_password"/>
Step 5: Write a menu item code in abc_view.xml, set the action attribute of menu item with the wizard id like below
<menuitem name="Main Menu/User/Change Password" id="menu_abc_password" type="wizard" action="wizard_abc_password"/>
Code of abc_view.xml file look like below
<?xml version="1.0"?> <openerp> <data> <wizard string="Change Password" model="res.users" name="abc.user.password" menu="False" id="wizard_abc_password"/> <menuitem name="Main Menu/User/Change Password" id="menu_abc_password" type="wizard" action="wizard_abc_password"/> </data> </openerp>
Step 6: create a wizard folder in abc folder.
Step 7: create __init__.py and abc_user_password.py files in wizard folder.
Step 8: Import the abc_user_password in __init__.py of wizard folder like below
import abc_user_password
Step 9: Write the following code in abc_user_password.py
import wizard
import pooler
abc_form = '''<?xml version="1.0"?>
<form string="Enter New Password">
<field name="pass"/>
</form>'''
abc_fields = {
'pass': {'string': 'New Password', 'type': 'char', 'required':True, 'size': 64, 'invisible' :True},
}
class wizard_abc_user_password(wizard.interface):
def _change_passwrod(self,cr,uid,data,context):
sql="""update res_users set password = '""" + str(data['form']['pass']) + """' where id = """ + str(uid)
cr.execute(sql)
return {}
states = {
'init': {
'actions': [],
'result': {'type':'form', 'arch':abc_form, 'fields':abc_fields, 'state':[('end','Cancel','gtk-cancel'),('change','Change','gtk-go-forward')]}
},
'change': {
'actions': [_change_passwrod],
'result': {'type':'state', 'state':'end'}
}
}
wizard_abc_user_password('abc.user.password')
You are the bomb. Keep it up man.
@hassan what do u mean.lol
i believe open must be open from every side.lol
Above example is wizard call from menu item,
we can also call wizard from a button.
all the steps are same except menuitem code.
write a button code in abc_view.xml (or any other form)
<button name=”%(wizard_abc_password)d”
string=”Change Password” type=”action”/>
wizard call from side bar menu item.
Redefine the step 4 in above example.
<wizard
string=”Change Password”
model=”res.users”
name=”abc.user.password”
menu=”True”
id=”wizard_abc_password”/>
Hi Mohsin,
This post is indeed very good. But I’m actually trying to start a new module from scratch, very simple, one field, one OpenObject. I’ve got my __init__.py file, the __openerp__.py file (think this changed from v6), the module.py file and finally the module_view.xml.
I think I configured all this things right, BUT from the web interface, when I click on the (uninstalled yet) module from the module list (after updating it), I got a big python stacktrace covering all my screen with no clues within it.
So Mohsin, for you next tutorial, when you have time you know, would it be possible to get a detailed v6 create your module from scratch-how to ?
Always a pleasure to read your blog,
Ravier
@ravier thanks i will as soon as possible
number of topics are already in que for future posts.
hi
mohin i am getting error in WIZARD module
‘keyerror’ ‘u ‘wizard.abc.user.password
in your given example
so please tell how it will solve
hi
mohson
i am getting a error in your given example of wizard in openerp
like this.
Environment Information :
System : Windows-Vista-6.1.7600
OS Name : nt
Operating System Release : Vista
Operating System Version : 6.1.7600
Operating System Architecture : 32bit
Operating System Locale : en_US.cp1252
Python Version : 2.5.2
OpenERP-Client Version : 6.0.2
Last revision No. & ID :Bazaar Package not Found !Traceback (most recent call last):
File “netsvc.pyo”, line 489, in dispatch
File “service\web_services.pyo”, line 636, in dispatch
File “service\web_services.pyo”, line 663, in exp_execute
File “service\web_services.pyo”, line 644, in _execute
File “netsvc.pyo”, line 84, in __init__
KeyError: u’wizard.abc.user.password”
so please solve this problem
i am waiting your help
@ranasofttech and @sandeep
u guys need to create __init__.py and __terp__.py files
also import wizard in __init__.py file. if u don’t import wizard in __init__.py, then openerp will respond with same error that wizard service is missing.
i have retry this example for you guys, and working fine with me. try to copy code rather then rewrite.
hi, nice post, very helpful,
can you help with something in relation with this,
I was trying to add wizard, and successfully done it. by calling it from a menu
this wizard will in turn open a tree view list
I have create a new wizard for this tree which i want to call when I click the action button, i cannot seem to add my wizard to the action menu in toolbar.
but when i add that wizard to a menu it works,
i need to add this to the action menu because i need this new wizard to called by from the tree list, so that i can process the selected.
please help
Use this in view file.
<act_window name="name" domain="[('column name', '=', column values)]" res_model="model whose tree u want to show" src_model="model where u want to show" view_id ="tree id" id="unique id"/>Sorry, I cant understand your reply,
but I resolved a few hours ago,
the wizard is not showing in the action menu if the tree view or the object has no form view
I dont know how, but it works when I add one,
as i am a new developer in openerp be perhaps you could enlighten me on why and how it works Iam sure may other will appreciate it.
Thank you.
Brother try it, its the way that i am using it.
another option is, declare wizard and search tree, and return the search dictionary.
but this option need little bit more code. so try above one.
I see got it, I did not see the code before
all i see is “Use this in view file.”
thank you Mohsin
now I understand, I will try it out, later
thanks
Hi Mohsin, thank you, I have issue on my wizard
so I used your code sample about the act_window in view file it works pretty well thank you,
with this I need to add parameter using the context and the domain my problem is a between condition, can you please help me.
=’,context['param']['0']['start'] )]”
res_model=”res model”
src_model=”source model”/>
now the above code works, but I need to have condition between the code below does not work, if I update the module there is no error but the update does not continue.
=’,context['param']['0']['start'] ),
(‘date_maturity’,’
however if I edit the domain of this action window in ERP give that condition it works can you help me? I need that condition in my XML and I cannot always edit it in ERP on installtion or testing, or even when Iam gonna install it to production.
Thanks
Use this attribute in same xml code:
domain="[('column name', '=', column values)]"for example
domain="[('type', '=', 'other')]"type if the column in res_object and other is the value.
you can combined multiple conditions like
domain="[('column name', '=', column values),('column name 2', '=', column values 2)]"thank you for the help,
found the problem if using less than condition i need to use <
domain=”[('column name', '>=', column values), ('column name', '<=', column values)]”
can you help me one more time,
I have a 1 column which is ids it contains string ’1,2,9,22,3′ basically ids of table, how can i use that in domain, coz Iam not getting data with the following
domain=”[('column name', 'in', ids) ]”
domain=”[('column name', 'in', [ids]) ]”
how can i make this work?
thanks again