jeudi 29 août 2013

How to create a basic module in OpenERP 7

It is very easy to create a module in OpenERP 7
  •  The following steps are required to create a new module "student" :
  1. Create a subdirectory in the .../OpenERP/Server/server/openerp/addons/  that name module "student".
  2.  Create a file Module description : __ openerp__.py
  3. Create the file containing Python objects : student.py
  4. Create .xml file that download data (views, menu items, data show ...) : student_view.xml
  5. Finaly create a file Module start : __init__.py
  • The __ openerp__.py file :
In the module directory created, you must add a __ openerp__.py file.
This file, which must be Python format is responsible for :
    1. Determine the XML files that will be analyzed during the initialization of the server, and also
    2. Determine the dependencies of the module created.
        This file must contain a Python dictionary with the following values​​:

        {
                "name" : "student",
                "version" : "0.1",
                "author" : "rsuna blog",
                "website" : "http://rsuna.blogspot.com/",
                "category" : "Unknown",
                "description": """ OpenERP Module test rsuna blog """,
                "depends" : ['base'],
                "init_xml" : [ ],
                "demo_xml" : [ ],
                "update_xml" : ['student_view.xml'],
                "installable": True
        }

        • The student.py file :
        from osv import fields,osv
        class student(osv.osv):
            _name = 'student'
            _columns = {
                'name': fields.char('Name',size=30,required=True, help='the name'),
                'first_name': fields.char('First Name',size=30,required=True, help='the first name'),
                'birth_date': fields.date('Birth Date',size=30,required=True, help='the birth date'),
                'email': fields.char('Email',size=50, help='the email'),
                'phone': fields.integer('Phone',size=30, help='the phone'),
            }
        student()

        • The student_view.xml file :
        <?xml version="1.0"?>
        <openerp>
        <data>
            <record model="ir.ui.view" id="view_student_form">
                <field name="name">student.form</field>
                <field name="model">student</field>
                <field name="type">form</field>
                <field name="arch" type="xml">
                    <form string="student">
                        <field name="name" select="1"/>
                        <field name="first_name" select="2"/>
                        <field name="birth_date" select="0"/>
                        <field name="email" select="0"/>
                        <field name="phone" select="0"/>
                    </form>
                </field>
            </record>
            <record model="ir.ui.view" id="view_student_tree">
                <field name="name">student.tree</field>
                <field name="model">student</field>
                <field name="type">tree</field>
                <field name="arch" type="xml">
                    <tree string="student">
                        <field name="name"/>
                        <field name="first_name"/>
                        <field name="birth_date"/>
                        <field name="email"/>
                        <field name="phone"/>
                    </tree>
                </field>
            </record>
            <record model="ir.actions.act_window" id="action_student">
                <field name="name">Student</field>
                <field name="res_model">student</field>
                <field name="view_type">form</field>
                <field name="view_mode">tree,form</field>
            </record>
                <menuitem name="Student/Student" id="menu_student" action="action_student"/>
        <menuitem name="Student" id="menu_student_student_item" parent="menu_student" action="action_student"/>
        </data>
        </openerp>

        • The __init__.py file :
        The __init__.py  file is like any Python module, executed at the beginning of the program. It needs to import the Python files to be loaded.

        So if you create a "student.py" file containing the description of your items, you must write a line in  __init__.py :

        - After restarts service openrerp.
        go to Configuration -> Module installs, and makes a search in the area of ​​search aver the module name "student"

        - Click on install
        Congratulation, module installed !!




        0 commentaires:

        Enregistrer un commentaire

        Share

        Twitter Delicious Facebook Digg Stumbleupon Favorites More