Session

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

Bases: object

Container for the OpenERP transactional stuff:

cr

The OpenERP Cursor

uid

The User ID as integer

pool[source]

The registry of models

context[source]

The current OpenERP’s context

browse(model, ids)[source]

Shortcut to openerp.osv.orm.BaseModel.browse

change_context(*args, **kwds)[source]

Context Manager: shallow copy the context, update it with values, then restore the original context on closing.

Parameters: values (dict) – values to apply on the context
change_user(*args, **kwds)[source]

Context Manager: temporarily change the user’s session and restablish the normal user at closing,

close()[source]

Close the cursor

commit()[source]

Commit the cursor

context[source]
create(model, values)[source]

Shortcut to openerp.osv.orm.BaseModel.create

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[source]
read(model, ids, fields)[source]

Shortcut to openerp.osv.orm.BaseModel.read

rollback()[source]

Rollback the cursor

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

Shortcut to openerp.osv.orm.BaseModel.search

write(model, ids, values)[source]

Shortcut to openerp.osv.orm.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(*args, **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