Session

class connector.session.ConnectorSession(cr, uid, context=None)[source]

Bases: object

Container for the OpenERP transactional stuff:

env

The Environment

cr

The OpenERP Cursor

uid

The User ID as integer

pool

The registry of models

context

The current OpenERP’s context

browse(model, ids)[source]

Shortcut to openerp.models.BaseModel.browse

change_context(**kwds)[source]

Context Manager: create a new Env with an updated context

It generates a new openerp.api.Environment used within the context manager, where the context is extended with the arguments. The original environment is restored at the closing of the context manager.

The extended context is either the provided context in which overrides are merged or the current context in which overrides are merged e.g.

# current context is {'key1': True}
r2 = records.with_context({}, key2=True)
# -> r2._context is {'key2': True}
r2 = records.with_context(key2=True)
# -> r2._context is {'key1': True, 'key2': True}

Warning

only recordsets read within the context manager will be attached to this environment. In many cases, you will prefer to use openerp.models.BaseModel.with_context()

change_user(**kwds)[source]

Context Manager: create a new Env with the specified user

It generates a new openerp.api.Environment used within the context manager, where the user is replaced by the specified one. The original environment is restored at the closing of the context manager.

Warning

only recordsets read within the context manager will be attached to this environment. In many cases, you will prefer to use openerp.models.BaseModel.with_context()

close()[source]

Close the cursor

commit()[source]

Commit the cursor

context
cr
create(model, values)[source]

Shortcut to openerp.models.BaseModel.create

classmethod from_env(env)[source]

Return a ConnectorSession from openerp.api.Environment

is_module_installed(module_name)[source]

Indicates whether a module is installed or not on the current database.

Use a convention established for the connectors addons: To know if a module is installed, it looks if an (abstract) model with name module_name.installed is loaded in the registry.

pool
read(model, ids, fields)[source]

Shortcut to openerp.models.BaseModel.read

rollback()[source]

Rollback the cursor

search(model, domain, limit=None, offset=0, order=None)[source]

Shortcut to openerp.models.BaseModel.search

uid
write(model, ids, values)[source]

Shortcut to openerp.models.BaseModel.write

class connector.session.ConnectorSessionHandler(db_name, uid, context=None)[source]

Bases: object

Allow to create a new instance of ConnectorSession for a database.

db_name

The name of the database we’re working on

uid

The User ID as integer

context

The current OpenERP’s context

Usage:

session_hdl = ConnectorSessionHandler(db_name, 1)
with session_hdl.session() as session:
    # work with session
session(**kwds)[source]

Context Manager: start a new session and ensure that the session’s cursor is:

  • rollbacked on errors
  • commited at the end of the with context when no error occured
  • always closed at the end of the with context
  • it handles the registry signaling