Connector

class connector.connector.Binder(environment)[source]

Bases: connector.connector.ConnectorUnit

For one record of a model, capable to find an external or internal id, or create the binding (link) between them

The Binder should be implemented in the connectors.

bind(external_id, binding_id)[source]

Create the link between an external ID and an OpenERP ID

Parameters:
  • external_id – external id to bind
  • binding_id (int) – OpenERP ID to bind
to_backend(binding_id, wrap=False)[source]

Give the external ID for an OpenERP binding ID (ID in a model magento.*)

Parameters:
  • binding_id – OpenERP binding ID for which we want the backend id
  • wrap – if False, binding_id is the ID of the binding, if True, binding_id is the ID of the normal record, the method will search the corresponding binding and returns the backend id of the binding
Returns:

external ID of the record

to_openerp(external_id, unwrap=False)[source]

Give the OpenERP ID for an external ID

Parameters:
  • external_id – external ID for which we want the OpenERP ID
  • unwrap – if True, returns the openerp_id else return the id of the binding
Returns:

a record ID, depending on the value of unwrap, or None if the external_id is not mapped

Return type:

int

unwrap_binding(binding_id, browse=False)[source]

For a binding record, gives the normal record.

Example: when called with a magento.product.product id, it will return the corresponding product.product id.

Parameters: browse – when True, returns a browse_record instance rather than an ID
unwrap_model()[source]

For a binding model, gives the normal model.

Example: when called on a binder for magento.product.product, it will return product.product.

class connector.connector.ConnectorUnit(environment)[source]

Bases: object

Abstract class for each piece of the connector:

Examples:

Or basically any class intended to be registered in a Backend.

get_binder_for_model(model=None)[source]

Returns an new instance of the correct Binder for a model

get_connector_unit_for_model(connector_unit_class, model=None)[source]

According to the current Environment, search and returns an instance of the ConnectorUnit for the current model and being a class or subclass of connector_unit_class.

If a model is given, a new Environment is built for this model.

Parameters:
  • connector_unit_class (connector.connector.ConnectorUnit) – ConnectorUnit to search (class or subclass)
  • model (str) – to give if the ConnectorUnit is for another model than the current one
classmethod match(session, model)[source]

Returns True if the current class correspond to the searched model.

Parameters:
class connector.connector.Environment(backend_record, session, model_name)[source]

Bases: object

Environment used by the different units for the synchronization.

backend

Current backend we are working with. Obtained with backend_record.get_backend().

Instance of: connector.backend.Backend

backend_record

Browsable record of the backend. The backend is inherited from the model connector.backend and have at least a type and a version.

session

Current session we are working in. It contains the OpenERP cr, uid and context.

model_name

Name of the OpenERP model to work with.

get_connector_unit(base_class)[source]

Searches and returns an instance of the ConnectorUnit for the current model and being a class or subclass of base_class.

The returned instance is built with self for its environment.

Parameters: base_class (connector.connector.ConnectorUnit) – ConnectorUnit to search (class or subclass)
set_lang(code)[source]

Change the working language in the environment.

It changes the lang key in the session’s context.

class connector.connector.MetaConnectorUnit(name, bases, attrs)[source]

Bases: type

Metaclass for ConnectorUnit.

Keeps a _module attribute on the classes, the same way OpenERP does it for the Model classes. It is then used to filter them according to the state of the module (installed or not).

model_name[source]

The model_name is used to find the class and is mandatory for ConnectorUnit which are registered on a Backend.

connector.connector.get_openerp_module(cls_or_func)[source]

For a top level function or class, returns the name of the OpenERP module where it lives.

So we will be able to filter them according to the modules installation state.

connector.connector.install_in_connector()[source]

Installs an OpenERP module in the Connector framework.

It has to be called once per OpenERP module to plug.

Under the cover, it creates a orm.AbstractModel whose name is the name of the module with a .intalled suffix: {name_of_the_openerp_module_to_install}.installed.

The connector then uses this model to know when the OpenERP module is installed or not and whether it should use the ConnectorUnit classes of this module or not and whether it should fire the consumers of events or not.