Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • OpenERP module configuration file

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 267
    Comment on it

    How to Make an OpenERP module configuration file?:

    It is very simple to Create a module in OpenErp. All you need to know is the basic structure of any module to be used in the system. So if you want to make a simple module in openerp, here below I am providing all information required.

    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.

    1->The _init_.py: It is a main file of openerp module configuration which 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

    2->The _openerp_.py: This file provides the description 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.

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

    book.py

    from osv import osv,fields
    class book(osv.osv):
    _name = "book"
    _description = "book details"
    _columns ={
    'name':fields.char('Name',size=128,required=True),
    'age' :fields.float('Age'),

    'active':fields.boolean('Active')
    }
    book() class book_detail(osv.osv):
    _name = "book"
    _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,
    4->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_form_view">
                    <field name="book">book.form</field>
                    <field name="model">book.detail</field>
                    <field name="type">form</field>
                    <field name="arch" type="xml">
    
                        <field name="name">
                        <field name="subject">
                        <field name="author">
                        <field name="publisher">
                        <field name="age">
    
                    </field>
                </field></field></field></field></field></record>
    
                <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="age">
                    </field></field></field></field></field></tree>
                    </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">
    
            </menuitem></menuitem></menuitem></menuitem></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: