OpenObject uses modules as feature containers, to foster maintainable and robust
development. The functionality in OpenERP is provided by modules.
Module Composition
A module may contain any of the following elements:
business objects: declared as Python classes extending the [Link] OpenObject class
data :
views,
menu,
wizards :
workflows,
demo
stateful
data
interactive
etc..
forms
reports : RML (XML format), MAKO or OpenOffice report templates, to be merged with any kind
of business data, and generate HTML, ODT or PDF reports.
Module Structure
A
module
is
created
within
Python Module Descriptor File [ __init__.py ]
import module, wizard, report
OpenERP Descriptor File [ __openerp__.py ]
the
server/bin/addons
directory
Objects,
Fields
and
Methods
The data in OpenERP is represented via 'Objects'. Every type of resource in openERP holds
an object. OpenERP modeling is based on 'objects' and the data is stored in 'Postgresql'
database.
Object Attributes
_name
_columns :
dictionary
_defaults
_inherit
object
of
dictionary
of
name
object
fields
(required)
fields
holding
(required)
default
values
: name of the parent object which the current object inherits from
_constraints
list
of
tuples
_sql_constraints :
list
of
tuples
of
constraints
defining
the
on
SQL
the
object
constraints
_rec_name
Alternative
field
to
use
as
name
_auto : Determines whether a corresponding PostgreSQL table must be generated
automatically from the object.
Field Types
Basically, there are 3 types of fields - simple,relational & functional
simple
boolean
'active'
:[Link]('active')
integer
'roll_no'
[Link]('Roll
No:)
float
'percentage':[Link]('Percentage')
char
'name'
[Link]('Name',
size=20,
required=True),
text
'note'
[Link]('Note')
'date'
[Link]('Date')
date
datetime
'time'
[Link]('Login Time')
selection
'gender'
[Link]((('M','Male'),('F','Female')),'Gender',required=True),
binary
'active'
[Link]('Active')
relational
many2one -
Relationship
towards
'class':
one2many -
Virtual
parent
fields.many2one('[Link]','class')
relationship
towards
multiple
'stud_name':fields.many2one('[Link]','Student
many2many -
Bidirectional
multiple
relationship
objects
Name'),
between
'mark_list':fields.one2many('[Link]','stud_rec_id','Mark
functional
object
objects
List')
Functional fields compute the values of the fields dynamically which is executed by a
function.
function(fnct,
arg=None,
fnct_inv=None,
fnct_inv_arg=None,
type='float',
fnct_search=None, obj=None, method=False, store=False, multi=False,...)
ORM
Methods
Parmeters
used:
cr:
database
uid:
ids:
id
list
context:
of
of
record
optional
connection
user
ids,
or
dictionary
of
single
(cursor)
performing
integer
contextual
the
when
there
parameters,
such
is
as
operation
only
user
one
id
language
[Link]('object_name')
can
be
used
to
create(cr,
obtain
model
uid,
class
from
values,
anywhere
context=None)
Creates a new record with the specified value , Returns: id of the new record
search(cr, uid, args, offset=0, limit=None, order=None, context=None, count=False)
Returns:
list
read(cr,
Returns:
of
user,
list
write(cr,
Updates
Deletes
of
records
ids,
dictionaries
uid,
ids,
records
with
given
ids
uid,
records
with
matching
the
fields=None,
of
unlink(cr,
browse(cr,
ids
with
requested
the
given
uid,
given
ids,
field
values
context=None)
values.
ids,
the
criteria
context=None)
values,
with
given
Returns:
True
context=None)
ids
Returns:
True
context=None)
Fetches records as objects, allowing to use dot-notation to browse fields and relations
Returns: object or list of objects requested
Views
Views describe how objects are exposed to the user. The views are written in XML. There
are two types of views- form view and tree view. Following is a form view of the student
record:
Menus and Actions
Menu
A menuitem is a shortcut for declaring an [Link] record and triggering actions defined.
Actions
Actions define the way of the system response according to the user triggering an action
like user login, clicking a button, etc..
It is very easy to create a module in OpenERP.
Find the below displayed screens. We will code to result this output.
Tree View
Form View
Few files needs to be created compulsory. We will take an example let say test_module
First of all, we will see the architecture of a typical OpenERP module.
__openerp__.py
2. __init__.py
1.
3. Python files
4. XMLFiles
1. Actions
2. Menu Entries
3. Reports
4. Wizards
All the modules are located in server/addons directory.
The following steps are necessary to create a new module test_module:
- create a subdirectory in the server/addons directory having module name test_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 test_module.py file, containing the description of your objects, you have to
write one line in __init__.py:
import test_module.py
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
1. determine the XML files that will be parsed during the initialization of the server, and also to
2. determine the dependencies of the created module.
This file must contain a Python dictionary with the following values:
{
"name" : "Test Module",
"version" : "1.1",
"author" : "Open",
"category" : "Test Base/Test Base",
"depends" : ["base"],
"init_xml" : [],
"demo_xml" : [],
"update_xml" : ["test_view.xml"],
"installable": True,
"active": True
}
The test_module.py file
from osv import osv
from osv import fields
class test_base([Link]):
Test Base Class
_name=[Link]
_columns={
name:[Link](Name,size=128,),
code:[Link](Code,size=64)
}
test_base()
The text_view.xml file
<?xml version=1.0 encoding=utf-8?>
<openerp>
<data>
<record model=[Link] id=test_base_form>
<field name=name>[Link]</field>
<field name=model>[Link]</field>
<field name=type>form</field>
<field name=arch type=xml>
<form string=Test Base>
<field name=name/>
<field name=code/>
</form>
</field>
</record>
<record model=[Link] id=test_base_tree>
<field name=name>[Link]</field>
<field name=model>[Link]</field>
<field name=type>tree</field>
<field name=arch type=xml>
<tree string=Test Base>
<field name=name/>
<field name=code/>
</tree>
</field>
</record>
<record model=[Link].act_window id=action_test_
seq>
<field name=name>Test Base</field>
<field name=res_model>[Link]</field>
<field name=view_type>form</field>
<field name=view_mode>tree,form</field>
</record>
<menuitem id=menu_test_base_main name=Test Base/>
<menuitem id=menu_test_base parent=menu_test_base_m
ain
name=Test Base action=action_test_seq/>
</data>
</openerp>