Concepts du connecteur

Le framework pour développer des connecteur est découplé en composants interagissant ensemble. Chacun d’eux peut être utilisé ou non dans une implémentation.

Un exemple d’implémentation est le Connecteur Odoo Magento.

Ce document les décrit d’un point de vue haut-niveau et donne des pointeurs vers des « how-to » plus concrets ou de petits tutoriels.

Événements

Reference: Events

Les événements sont des points d’accroche dans Odoo sur lesquels on peut brancher des actions. Ils sont basés sur le motif de conception « Observateur ».

Le même événement peut être partagé entre plusieurs connecteurs, facilitant ainsi leur implémentation. Par exemple, le module connector_ecommerce qui est une extension du framework avec des capacités courantes pour le e-commerce, ajoute ses propres événements dédiés au e-commerce.

Un développeur de connecteur est principalement intéressé par :

  • adding and listening to events (see Events)

Queue de jobs

Reference: Queue

This feature is part of a standalone addon, but is a prerequisite for the connector framework.

The module is queue_job in https://github.com/OCA/queue.

Un développeur de connecteur est principalement intéressé par :

  • Delay a job (see the decorator job())

Backend

Reference: Backend Model

The Backend Model is what represents the external service / system we synchronize with. The name on the backend indicates what is the collection the Components will be registered into. Put another way: every backend has its own collection of Components.

It must use an _inherit on connector.backend.

connector.backend inherits odoo.addons.component.models.collection.Collection which has a odoo.addons.component.models.collection.Collection.work_on() that will be used as entrypoint for the component system. This method returns a WorkContext

WorkContext

Reference: WorkContext

A WorkContext is the work environment or context that will be passed transversally through all the components. This is also the entrypoint to the component system.

Un développeur de connecteur est principalement intéressé par :

Component

Reference: Components

Component are pluggable classes used for the synchronizations with the external systems (or anything!)

The Components system has been extracted in a standalone addon (component), which means it can really be used in a totally different way.

The connector defines some base components, which you can find below. Note that you can and are encouraged to define your own Components as well.

Mappings

The base class is connector.components.mapper.Mapper.

In your components, you probably want to inherit from:

  • _inherit = 'base.import.mapper'

  • _inherit = 'base.export.mapper'

And the usages for the lookups are:

  • import.mapper

  • export.mapper

Un mapping convertit un enregistrement externe en un enregistrement Odoo et inversement.

Il prend en charge :

les mapping directs

Le champ a est écrit dans le champ b.

Les mapping par méthode

Une méthode est utilisée pour convertir un ou plusieurs champs en un ou plusieurs autres champs, avec transformation éventuelle. Il peut être filtré, par exemple appliqué uniquement lorsque l’enregistrement est créé ou quand les champs source sont modifiés.

Sous-mapping

Un sous-enregistrement (ligne d’un bon de commande) est converti grâce à un autre Mapper

See the documentation of the class for more details.

Synchroniseurs

The base class is connector.components.synchronizer.Synchronizer.

In your components, you probably want to inherit from:

  • _inherit = 'base.importer'

  • _inherit = 'base.exporter'

And the usages for the lookups are:

  • importer

  • exporter

However, in your implementation, it is advised to use more refined usages such as:

  • record.importer

  • record.exporter

  • batch.importer

  • batch.exporter

A synchronizer orchestrates a synchronization with a backend. It can be a record’s import or export, a deletion of something, or anything else. For instance, it will use the mappings to convert the data between both systems, the backend adapters to read or write data on the backend and the binders to create the link between them.

Adaptateurs de backend

The base class is connector.components.backend_adapter.BackendAdapter.

In your components, you probably want to inherit from:

  • _inherit = 'base.backend.adapter'

  • _inherit = 'base.backend.adapter.crud'

And the usages for the lookups are:

  • backend.adapter

Un adaptateur externe possède une interface commune pour parler avec le backend. Il traduit les commandes basiques (recherche, lecture, écriture) vers le protocole utilisé par le backend.

Binders (Liants)

The base class is connector.components.binder.Binder.

In your components, you probably want to inherit from:

  • _inherit = 'base.binder'

And the usages for the lookups are:

  • binder

Binders are components that know how to find the external ID for an Odoo ID, how to find the Odoo ID for an external ID and how to create the binding between them. A default implementation is available and can be inherited if needed.

Listeners

The base class is connector.components.listener.ConnectorListener.

In your components, you probably want to inherit from:

  • _inherit = 'base.connector.listener'

This is where you will register your event listeners. See addons.component_event.components.event.

Bindings (Liaisons)

Reference: Binding Model

A binding represents the link of a record between Odoo and a backend.

L’implémentation proposée pour les connecteurs utilise largement les capacités de l”_inherits.

Disons que nous importons un client depuis Magento.

Nous créons un modèle magento.res.partner, qui _inherits res.partner.

Ce modèle, appelé modèle de binding (liaison), connaît les ID du partner dans Odoo, l’ID dans Magento et la relation avec le modèle backend.

Il stocke également toutes les métadonnées nécessaires à ce client venant de Magento

Point de contrôle

Un point de contrôle est un enregistrement du modèle connector.checkpoint lié à un modèle et un enregistrement. Les connecteurs peuvent en créer de nouveaux quand l’utilisateur a besoin de vérifier des documents importés.