Amorcer la création un nouveau connecteur

Nous allons voir les étapes pour amorcer la création d’un nouveau connecteur

À côté de ça, vous devriez utiliser les connecteurs existants pour avoir des exemples réels d’implémentation:

Be aware that the connector API has changed in Odoo 10.0, so the examples might be outdated.

Du code boilerplate est nécessaire, donc ce document va vous guider à travers différentes étapes. Consultez également les Conventions de nommage.

Pour cet exemple nous allons imaginer que nous devons synchroniser Odoo avec une machine à café.

Odoo Manifest

Comme nous voulons synchroniser Odoo avec une machine à café, nous allons nommer notre connecteur connector_coffee

First, we need to create the Odoo addons itself, editing the connector_coffee/__manifest__.py manifest.

 # -*- coding: utf-8 -*-
 {'name': 'Coffee Connector',
  'version': '1.0.0',
  'category': 'Connector',
  'depends': ['connector',
              ],
  'author': 'Myself',
  'license': 'LGPL-3',
  'description': """
 Coffee Connector
 ================

 Connect Odoo to my coffee machine.

 Features:

 * Poor a coffee when Odoo is busy for too long
 """,
  'data': [],
  'installable': True,
 }

Il y a 2 points à noter :

  • It depends from connector. connector itself depends from queue_job, component and component_event. queue_job is in the OCA/queue repository.

  • La catégorie du module doit être Connector.

Bien sûr, nous devons aussi créer le fichier __init__.py où nous plaçons les imports de nos modules Python.

Modèle du backend

Reference: Backend Model

We need to create a Backend representing the external service. Every record we synchronize will be linked with a record of coffee.backend. This backend is our collection of Components.

The coffee.backend model is an _inherit of connector.backend. In connector_coffee/models/coffee_binding.py:

from odoo import api, fields, models


class CoffeeBackend(models.Model):
    _name = 'coffee.backend'
    _description = 'Coffee Backend'
    _inherit = 'connector.backend'

    location = fields.Char(string='Location')
    username = fields.Char(string='Username')
    password = fields.Char(string='Password')

Notes :

  • We can other fields for the configuration of the connection or the synchronizations.

Binding abstrait

Reference: Binding Model

In order to share common features between all the bindings (see Bindings (Liaisons)), create an abstract binding model.

It can be as follows (in connector_coffee/models/coffee_binding.py):

from odoo import models, fields


class CoffeeBinding(models.AbstractModel):
    _name = 'coffee.binding'
    _inherit = 'external.binding'
    _description = 'Coffee Binding (abstract)'

    # odoo_id = odoo-side id must be declared in concrete model
    backend_id = fields.Many2one(
        comodel_name='coffee.backend',
        string='Coffee Backend',
        required=True,
        ondelete='restrict',
    )
    coffee_id = fields.Integer(string='ID in the Coffee Machine',
                               index=True)

Notes :

  • This model inherit from external.binding

  • Any number of fields or methods can be added

Components

Reference: Components

We’ll probably need to create synchronizers, mappers, backend adapters, binders and maybe our own kind of components.

Their implementation can vary from a project to another. Have a look on the Odoo Magento Connector and Odoo Prestashop Connector projects.