Basics of developing a simple module in OpenERP

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 osv.osv OpenObject class
data : views, menu, workflows, demo data etc..
wizards : stateful interactive 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


Python Module Descriptor File   [ __init__.py ]


     import module, wizard, report

OpenERP Descriptor File [ __openerp__.py ]


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  :  object name   (required)
_columns : dictionary  of object fields    (required)
_defaults  : dictionary of fields holding default values
_inherit   : name of the parent object which the current object inherits from
_constraints  : list of tuples of constraints on the object
_sql_constraints : list of tuples defining the SQL 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‘ :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
        ‘date‘ : fields.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 a parent object
        ‘class‘: fields.many2one(‘student.det’,’class’)
   one2many – Virtual relationship towards multiple objects
        ‘stud_name‘:fields.many2one(‘stud.name’,’Student Name’),
    many2many – Bidirectional multiple relationship between objects
       ‘mark_list‘:fields.one2many(‘stud.mark’,’stud_rec_id’,’Mark List’)
functional

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 connection (cursor)
   uid: id of user performing the operation
   ids: list of record ids, or single integer when there is only one id
   context: optional dictionary of contextual parameters, such as user  language
self.pool.get(‘object_name’)
    can be used to obtain a model class from  anywhere
create(cr, uid, values, 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 of ids of records matching the given criteria
read(cr, user, ids, fields=None, context=None)
Returns: list of dictionaries with requested field values
write(cr, uid, ids, values, context=None)
    Updates records with given ids with the given values.  Returns: True
unlink(cr, uid, ids, context=None)
    Deletes records with the given ids . Returns: True
browse(cr, uid, ids, 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 ir.ui.menu 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..

Comments

Anonymous: Hello and thank you very much for sharing this information. I was wondering whether you could help me or point me in the right direction to solve something that seems to be very easy but daunting for me. If I may explain, my goal is to assign the incoterm to the supplier (res.partner) and than pull this data on the purchase order whenever I enter the supplier name with the option to alter it on the PO as occasionally the incoterm changes for the same supplier. I managed so far to create the field many2one in res.partner table pulling the information from stock.incoterms table and the incoterm stores correctly on the res.partner table. I am stuck from this moment on trying to get the incoterm of a supplier in a new field in purchase order when I enter the supplier name. I hope it makes sense and would be grateful if you could help me out as all the posts I searched don't seem to address this situation Many thanks Mangofunky".

Leave a Reply

Your email address will not be published. Required fields are marked *

  1. David says:

    Thanks for the post, it is hard to find good information about this subject

  2. Anonymous says:

    Hello and thank you very much for sharing this information.
    I was wondering whether you could help me or point me in the right direction to solve something that seems to be very easy but daunting for me.
    If I may explain, my goal is to assign the incoterm to the supplier (res.partner) and than pull this data on the purchase order whenever I enter the supplier name with the option to alter it on the PO as occasionally the incoterm changes for the same supplier.
    I managed so far to create the field many2one in res.partner table pulling the information from stock.incoterms table and the incoterm stores correctly on the res.partner table.
    I am stuck from this moment on trying to get the incoterm of a supplier in a new field in purchase order when I enter the supplier name. I hope it makes sense and would be grateful if you could help me out as all the posts I searched don’t seem to address this situation
    Many thanks
    Mangofunky

© 2020 Zesty Beanz Pvt Ltd All Rights Reserved.