Professional Documents
Culture Documents
Module Composition: Import
Module Composition: Import
Module Composition: Import
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
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
Field Types
Basically, there are 3 types of fields - simple,relational & functional
simple
boolean
'active'
:fields.boolean('active')
integer
'roll_no'
fields.integer('Roll
No:)
float
'percentage':fields.float('Percentage')
char
'name'
fields.char('Name',
size=20,
required=True),
text
'note'
fields.text('Note')
'date'
fields.date('Date')
date
datetime
'time'
fields.date('Login Time')
selection
'gender'
fields.selection((('M','Male'),('F','Female')),'Gender',required=True),
binary
'active'
fields.binary('Active')
relational
many2one -
Relationship
towards
'class':
one2many -
Virtual
parent
fields.many2one('student.det','class')
relationship
towards
multiple
'stud_name':fields.many2one('stud.name','Student
many2many -
Bidirectional
multiple
relationship
objects
Name'),
between
'mark_list':fields.one2many('stud.mark','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',
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
self.pool.get('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:
Actions
Actions define the way of the system response according to the user triggering an action
like user login, clicking a button, etc..
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.
name:fields.char(Name,size=128,),
code:fields.char(Code,size=64)
}
test_base()
The text_view.xml file