Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating a very basic module in OpenErp 6.1

    • 0
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 318
    Comment on it

    Creating a module in OpenErp is very simple. All you need to know is the basic skeleton of any module to be used in the system. There are four major files that build up your module:

    1.) init.py file

    2.) openerp.py file

    3.) mymodel.py file

    4.) mymodel_view.xml file

    All four files in a folder named as your_module, here I am using book as the name of my module.

    The _init_.py: This one is the main file that is used to import all the model/classes in your module, the folders like reports, wizards, tests, images etc.

    Simply create a python file using IDLE or any other text editor like Notepad ++ and write the following code:

    import book

    The _openerp_.py: This file describes all about you module. You can create your own or copy any openerp.py from other module, copy in you folder and edit it. The file looks like:

    {

    "name" : "Book",

    "version" : "1.0",

    "author" : "Evontech",

    "website" : "http://www.evontech.com/",

    "category" : "Generic Modules/Others",

    "depends" : ["base"],

    "description" : "Simple demo module made on books information",

    "initxml" : ["bookview.xml"],

    "active": False,

    "installable": True

    }

    Where these attributes in the left are:

    Name: name of the module,

    Version: the version of your module if any,

    Author: the author of the module,

    Website: website of the author if you want to upload your module later on the web,

    Category: the category of the module,

    Depends: the module list on which this module depends on, separated by a comma,

    Description: small description on you module,

    Init_xml: list of all the xml files to be loaded when the OpenErp service is started,

    Active: true or false(default), determines whether the module is installed on the database creation,

    Installable: true or false, whether the module is installable or not.

    mymodule.py: This one is the model you usually create in any other module. In python take care of the indentation or else you will get the errors.

    book.py

    from osv import osv,fields
    
    class book(osv.osv):
    
        _name = "book"
    
        _description = "Books List"
    
        _columns = {
                'name':fields.char('Name',size=128,required=True),
                'price' :fields.float('Price'), 
                'active':fields.boolean('Active')
                    }
    
    book()
    
    class book_detail(osv.osv):
    
        _name = "book.detail"
    
        _inherit     = "book"
    
        _columns = {
                            'subject':fields.char('Subject',size=50),
                'author': fields.char('Author', size=30),
                'publisher': fields.char('Publisher',size=50),
                   }
    book_detail()
    

    _name: name of the model, this will be the name of your table in the database,

    _description: description for your model, what it is about,

    _inherit: for the model that it is extended from if any, use _inherits for multiple inheritance,

    _columns: for the fields or columns your table will have,

    _defaults: for providing the fields that will have their default values,

    mymodule_view.xml: This file is having the code that decides how the module looks like, the forms, tree or list view, the menus, and menu items.

    book_view.xml

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data>
            <record model="ir.ui.view" id="book_tree_view">
                <field name="book">book.tree</field>
                <field name="model">book.detail</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                <tree string="Books">
                    <field name="name"/>
                    <field name="subject"/>
                    <field name="author"/>
                    <field name="publisher"/>
                    <field name="price"/>
                </tree>
                </field>
            </record>
            <record model="ir.ui.view" id="book_form_view">
                <field name="book">book.form</field>
                <field name="model">book.detail</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                <form string="Books">
                    <field name="name"/>
                    <field name="subject"/>
                    <field name="author"/>
                    <field name="publisher"/>
                    <field name="price"/>
                </form>
                </field>
            </record>
            <record model="ir.actions.act_window" id="action_book_form">
                <field name="name">book</field>
                <field name="res_model">book</field>
            </record>
    
            <menuitem name="book" icon="terp-project" id="book_menu"/>
            <menuitem name="Book Details" parent="book_menu" id="book_menu_mainform" action="action_book_form"/>
            <menuitem name="Add" parent="book_menu_mainform" id="book_add" />
            <menuitem name="Reporting" parent="book_menu" id="book_report" />
    </data>    
    </openerp>
    

    The basic structure of any view in the OpenErp module:

    <?xml version="1.0" encoding="utf-8"?>
    <openerp>
        <data> </data>
    </openerp>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
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: