It is very easy to create a module in OpenERP 7
- The following steps are required to create a new module "student" :
- Create a subdirectory in the .../OpenERP/Server/server/openerp/addons/ that name module "student_speciality".
- Create a file Module description : __ openerp__.py
- Create the file containing Python objects : student_speciality.py
- Create .xml file that download data (views, menu items, data show ...) : student_speciality_view.xml
- Finaly create a file Module start : __init__.py
- The __ openerp__.py file :
This file, which must be Python format is responsible for :
- Determine the XML files that will be analyzed during the initialization of the server, and also
- Determine the dependencies of the module created.
{
"name" : "student_speciality",
"version" : "0.1",
"author" : "rsuna blog",
"website" : "http://rsuna.blogspot.com/",
"category" : "Unknown",
"description": """ OpenERP Module with 2 class mano2one test rsuna blog """,
"depends" : ['base'],
"init_xml" : [ ],
"demo_xml" : [ ],
"update_xml" : ['student_speciality_view.xml'],
"installable": True
}
- The student_speciality.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'),
'level': fields.many2one('specialty','Specialty', help='the Specialty'),
}
student()
class specialty(osv.osv):
_name = 'specialty'
_columns = {
'name': fields.char('Name specialty',size=50,required=True, help='the name specialty'),
'level': fields.char('Level',size=50, help='the level'),
}
specialty()
- The student_speciality_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"/>
<field name="level" 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"/>
<field name="level"/>
</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"/>
<menuitem name="Student" id="menu_student_item" parent="menu_student" action="action_student"/>
<record model="ir.ui.view" id="view_specialty_form">
<field name="name">specialty.form</field>
<field name="model">specialty</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="specialty">
<field name="name" select="1"/>
<field name="level" select="2"/>
</form>
</field>
</record>
<record model="ir.ui.view" id="view_specialty_tree">
<field name="name">specialty.tree</field>
<field name="model">specialty</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="specialty">
<field name="name"/>
<field name="level"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="action_specialty">
<field name="name">Specialty</field>
<field name="res_model">specialty</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Specialty/Specialty" id="menu_specialty" action="action_specialty"/>
<menuitem name="Specialty" id="menu_specialty_item" parent="menu_specialty" action="action_specialty"/>
</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_speciality"
- Click on install
Congratulation, module installed !!
So if you create a "student.py" file containing the description of your items, you must write a line in __init__.py :
import student_speciality
- After restarts service openrerp.
go to Configuration -> Module installs, and makes a search in the area of search aver the module name "student_speciality"
- Click on install
Congratulation, module installed !!


