Custom Modules/Addons
I am writing on custom openerp module development,This is
meant to kick start you development of modules in open erp.It will enable you
use the strong features of Object oriented software development.
Few file needs to be created compulsory.
We will take an
example let say – “project1_module”
First of all, we will see the architecture of a typical
OpenERP module.
__openerp__.py
__init__.py
Python files
XMLFiles
Actions
Menu Entries
Reports
Wizards
i.
All the modules are located in server/addons directory.
The following steps are necessary to create a new module
“project_module”:
- create a subdirectory in the server/addons directory
having module name project_module.
- create a module description file: __openerp__.py
- create the Python file containing the objects.
- create .xml files that download the data (views, menu
entries, demo data, …).
- optionally create reports, wizards or workflows.
We will see each files introduction one by one.
The __init__.py file:
The __init__.py file is, like any Python module, executed
at the start of the program. It needs to import
the Python files that need to be loaded.
So, if you create a “project1_module.py” file, containing the
description of your objects, you have to write one line in __init__.py:
import project1_module.py
fig a.)
The __openerp__.py file
In the created module directory, you must add a __openerp__.py
file. This file, which must be in Python format, is responsible to
determine the XML files that will be parsed during the
initialization of the server, and also to
determine the dependencies of the created module.
This file must contain a Python dictionary with the
following values:
{
"name" : "Project1 Module",
"version" : "1.1",
"author" : "Open",
"category" : "Project Base/Project Base",
"depends" : ["base"],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["project_view.xml"],
"installable": True,
"active": True
}
"name" : "Project1 Module",
"version" : "1.1",
"author" : "Open",
"category" : "Project Base/Project Base",
"depends" : ["base"],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["project_view.xml"],
"installable": True,
"active": True
}
fig b.)
The project1_module.py file
from osv import osv
from osv import fields
class project_base(osv.osv):
”’Project Base Class”’
_name=‘project.base’
_columns={
‘name’:fields.char(“Name”,size=128,),
‘code’:fields.char(“Code“,size=64)
}
project_base()
fig c.)
The project_view.xml file
<?xml version=“1.0″
encoding=“utf-8″?>
<openerp>
<data>
<record model=“ir.ui.view” id=“project_base_form”>
<field name=“name”>project.base.form</field>
<field name=“model”>project.base</field>
<field name=“type”>form</field>
<field name=“arch” type=“xml”>
<form string=“Project Base”>
<field name=“name”/>
<field name=“code”/>
</form>
</field>
</record>
<record model=“ir.ui.view”
id=“project_base_tree”>
<field name=“name”>project.base.tree</field>
<field name=“model”>project.base</field>
<field name=“type”>tree</field>
<field name=“arch” type=“xml”>
<tree string=“Project Base”>
<field name=“name”/>
<field name=“code”/>
</tree>
</field>
</record>
<record model=“ir.actions.act_window”
id=“action_project_seq”>
<field
name=“name”>Project Base</field>
<field name=“res_model”>project.base</field>
<field name=“view_type”>form</field>
<field name=“view_mode”>tree,form</field>
</record>
<menuitem id=“menu_project_base_main”
name=“Project Base”/>
<menuitem id=“menu_project_base”
parent=“menu_project_base_main”
name=“Project Base” action=“action_project_seq”/>
</data>
</openerp>
fig d.)
No comments:
Post a Comment