Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • How to create Wizards using osv.memory in OpenErp 6.1

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 2.14k
    Comment on it

    To create a wizard for a module, we need to create a wizard folder; this folder will be imported in our main of the module. The wizard folder will contain another which will import all the wizard class files.

    The Wizard Folder

    The wizard folder consists of the following:

    2. or more wizards
    3. wizard_view.xml or more wizard views

    import add_subjects

    from osv import osv,fields
    class add_subjects(osv.osv_memory):
        _name = "add.subjects"
        _description = "subjects"
        _columns = {
                    'subject_line':fields.one2many('subject.line', 'subject_id', 'Subjects'),
        def _get_subjects(self,cr, uid, ctx):
            if 'active_id' in ctx:
                return self.pool.get('student').browse(cr,uid,ctx['active_id']).subject_line
            return False
        _defaults = {
                    'subject_line': _get_subjects
        def subjects(self, cr, uid, ids, context=None):
            if 'active_id' in context:
                                                     {'subject_line' : subject})
             return{'type': 'ir.actions.act_window_close',}

    The major difference between a model and a wizard is the osv.osv_memory. In OpenErp 6.1, any wizard you create has osv.osv_memory as a parameter, whereas a model will have osv.osv. Declare all the necessary fields and methods.


    <?xml version="1.0" encoding="utf-8"?>
            <record id="view_add_subjects" model="ir.ui.view">
                <field name="name">add.subjects.form</field>
                <field name="model">add.subjects</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                <form string="Subjects">
                        <group colspan="4" >
                            <separator string="Adding Subjects" colspan="4"/>
                            <field colspan="4" name="subject_line" nolabel="1" mode="tree,form">
                                    <tree string="Subject Lines">                                    
                                        <field name="title"/>
                                        <field name="out_of"/>
                                        <field name="marks"/>                                    
                               <separator string="" colspan="4" />                    
                            <button icon="gtk-cancel" special="cancel" string="Cancel"/>
                            <button icon="gtk-ok" name="subjects" string="Add" type="object"/>                 
            <record id="action_add_subjects" model="ir.actions.act_window">
                <field name="name">Add Subjects</field>            
                <field name="res_model">add.subjects</field>
                <field name="view_type">form</field>
                <field name="view_mode">tree,form</field>
               <field name="view_id" ref="view_add_subjects"/>
               <field name="target">new</field>
            <act_window id="action_add_subjects_values"
                key2="client_action_multi" name="Subjects Information"
                res_model="add.subjects" src_model="student"
                view_mode="form" target="new" view_type="form"/>

    Note the record action for this wizard; we have to create wizards action this way only. The attribute target is important and should always have value new so that it opens as a new window. The defines your wizards action in the ir.act_window table of your opener database.

    The wizard is complete, you can add as many wizards as you wish and import all of them in the of the wizard folder. Finally import this folder in the main file of your module like:

    import student

    import wizard

    Now in your view file from where you want to launch this wizard create a button and define the action id of the wizard as the name of the button:


    <button name="%(action_add_subjects)d" string="Add Subjects" type="action"/>

    "name" : "Student Information",
    "version" : "1.0",
    "author" : "EvonTech",
    "category" : "Generic Modules/Others",
    "depends" : ["base"],
    "description" : "Student Information Management Module",
    "init_xml": ["wizard/add_subjects_view.xml","student_view.xml"],
    "update_xml" : [],
    "demo_xml" : [],
    "active" : False,
    "installable" : True

    Note: Always define your wizard views before the main view file in the init_xml attribute otherwise you will get an error No such external_id found: module.wizard_view.xml.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: