tags:

views:

28

answers:

1

Here a way to develop OpenERP

class stock_incoterms(osv.osv):

_name = "stock.incoterms"
_description = "Incoterms"
_columns = {
    'name': fields.char('Name', size=64, required=True),
    'code': fields.char('Code', size=3, required=True),
    'active': fields.boolean('Active'),
}
_defaults = {
    'active': lambda *a: True,
}

stock_incoterms()
This is typical OpenERP model and map to table name stock_incoterms.
The columns property defines columns for the table The default property defines default value for each column.

My questions are:

How to implement this in Python?
When running stock_incoterms(), OpenERP will read this model, generate the table with these defined columns.
After that, suppose I created a record in this table, then I ask give me the model of this class, ex
stock_incoterm = stock_incoterms.get(1) ( record id in db)
Now i can access
stock_incoterm.name
stock_incoterm.code
........

This way of defining model is kind of Meta Programming but I don't know how to write it in Python.

Could anyone guide me the details behind or some good links about meta programming in Python?

+2  A: 

The OpenERP developer book is the best place to start looking. It sounds like you want to add a new table called stock_incoterm. I would recommend you start a new module and add the table to it, along with a screen and some menu items to edit the table. The developer book has a chapter on developing modules.

Once you've got all that set up, your code to access fields on a record would look something like this:

class stock_incoterms(osv.osv):
    # ...

    def do_something(self, cr, uid, ids):
        for stock_incoterm in self.browse(cr, uid, ids):
            name = stock_incoterm.name

            # ...
Don Kirkby
I've read this book. My purpose is how to implement thing like OpenERP. I should try to read the source code but I'd like to get a hint before diving in.Thanks
Iapilgrim