Home > OpenERP, Python, XML > OpenERP Module Development Wizard

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')

Categories: OpenERP, Python, XML
  1. Hassan
    January 28, 2011 at 1:13 pm

    You are the bomb. Keep it up man.

    • January 28, 2011 at 4:35 pm

      @hassan what do u mean.lol
      i believe open must be open from every side.lol

  2. January 28, 2011 at 4:50 pm

    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”/>

  3. January 29, 2011 at 6:03 am

    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”/>

  4. Ravier
    February 3, 2011 at 4:08 pm

    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

    • February 3, 2011 at 6:02 pm

      @ravier thanks i will as soon as possible
      number of topics are already in que for future posts.

  5. September 28, 2011 at 11:33 am

    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

  6. September 28, 2011 at 11:40 am

    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

  7. September 29, 2011 at 10:06 am

    @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.

  8. February 7, 2012 at 1:08 am

    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

    • February 7, 2012 at 9:38 am

      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"/>
      
      • February 7, 2012 at 9:43 am

        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.

  9. February 7, 2012 at 10:01 am

    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.

    • February 7, 2012 at 11:03 am

      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

  10. February 8, 2012 at 9:01 am

    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

  11. February 8, 2012 at 9:15 am

    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)]"
    
  12. February 8, 2012 at 10:48 am

    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

  13. Nitika
    February 22, 2013 at 6:18 am

    Where is the view file for the wizard since in my case there is no action when i click on the change password menuitem

  14. Dhiren Mehta
    April 11, 2013 at 10:23 am

    Hello Mohsin,
    Your blog is wonderful. Your expertise in openerp and concepts is appreciated.

    I am new to openerp, and need your help.

    I have installed openerp-server-6.0.4-20130301-r3659 and openerp-web-6.0.4-20130301-r4906 on ubuntu server 12.04 (installed on virtualbox).

    Directory details are
    1. /opt/openerp/server
    2. /opt/openerp/web

    OpenERP works fine till this point with Sales and Accounting modules. Which means 3 options visible are “Sales”, “Accounting” and “Administration”. And below each there is menu visible on left side of screen.

    Now I start addition of new module as per steps mentioned by you.

    1. Created directory abc in /opt/openerp/server/bin/addons
    2. Created directory wizard in /opt/openerp/server/bin/addons/abc
    3. Created file abc_view.xml in /opt/openerp/server/bin/addons/abc and added code mentioned in step 5
    4. Created file __init__.py in /opt/openerp/server/bin/addons/abc/wizard and added code mentioned in step 8.
    5. Created abc_user_password.py file in /opt/openerp/server/bin/addons/abc/wizard and added code mentioned in step 9.
    6. Restarted openerp-server and openerp-web after this.
    7. Could not see the expected results.

    Basically I am looking for module “Abc” visible along with “Sales”, “Accounting” and “Administration”, and later add left side menu to module “Abc”.

    Please let me know where am I making mistake or missing out.

    Thanks in advance.

    Regards
    Dhiren

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: