Help

2

Where is pool.get() defined in OpenERP source?

Avatar
Antanas

By looking at addons, that come with OpenERP source, one can tell that

self.pool.get('model.name')

is frequently used in model methods.

Where is this "pool" and "get()" defined in OpenERP source code? I would like to look at it's documentation (docstrings).

Avatar
Discard
2 Answers
1
Avatar
xingtongjie
Best Answer

In /server/openerp/osv/orm.py

class BaseModel(object):

def __init__(self, pool, cr):

    """ Initialize a model and make it part of the given registry.

    - copy the stored fields' functions in the osv_pool,
    - update the _columns with the fields found in ir_model_fields,
    - ensure there is a many2one for each _inherits'd parent,
    - update the children's _columns,
    - give a chance to each field to initialize itself.

    """
    pool.add(self._name, self)
    self.pool = pool

pool is registry

in /server/openerp/pooler.py

def get_db_and_pool(db_name, force_demo=False, status=None, update_module=False):

"""Create and return a database connection and a newly initialized registry."""

 registry = RegistryManager.get(db_name, force_demo, status, update_module)

return registry.db, registry

/server/openerp/modules/registry.py

class Registry(object): """ Model registry for a particular database.

The registry is essentially a mapping between model names and model
instances. There is one registry instance per database.

"""

def __init__(self, db_name):
    self.models = {}    # model name/model instance mapping

def get(self, model_name):

    """ Return a model for a given name or None if it doesn't exist."""

    return self.models.get(model_name)

I understand pool today, above i find pool 's source code.

3 Comments
Avatar
Discard
Avatar
xingtongjie
-

the pool is pool of module`s instance

Avatar
xingtongjie
-

Has nothing to do with db cursor, every model has its cr. realize 'read(),write() etc 'fuction operation.

Avatar
xingtongjie
-

Where init module, the pool is passed into module.

0
Avatar
Andreas Maertens
Best Answer

/server/openerp/pooler.py

1 Comment
Avatar
Discard

Did you find it there?