Modèles¶
Backend Model¶
-
class
connector.models.backend_model.ConnectorBackend[source]¶ Bases :
odoo.models.BaseModelUne instance d’un backend externe auquel se synchroniser
Les backends doivent
_inheritce modèle dans les modules des connecteurs.The components articulates around a collection, which in the context of the connectors is called a Backend.
It must be defined as a Model that inherits from
'connector.backend'.Exemple avec le connecteur Magento
# in connector_magento/models/magento_backend.py class MagentoBackend(models.Model): _name = 'magento.backend' _inherit = 'connector.backend' _description = 'Magento Backend' # the version in not mandatory @api.model def _select_versions(self): """ Available versions Can be inherited to add custom versions. """ return [('1.7', 'Magento 1.7')] location = fields.Char(string='Location', required=True) username = fields.Char(string='Username') password = fields.Char(string='Password') versions = fields.Selection( selection='_select_versions', required=True )
Binding Model¶
-
class
connector.models.backend_model.ExternalBinding[source]¶ Bases :
odoo.models.BaseModelUn modèle abstrait pour une liaison à des enregistrements externes
Un binding externe est une liaison entre un backend et Odoo. Par exemple, pour un partner, cela peut être
magento.res.partnerou pour un article,magento.product.Le modèle final sera un
_inheritsdu modèle Odoo et va_inheritce modèle.Il aura une relation vers l’enregistrement (via
_inherits) et vers le modèle backend concret (par exemplemagento.backend).Il contiendra également toutes les données relatives aux backend pour l’enregistrement.
Il nécessite d’implémenter au moins ces champs :
- odoo_id
- Le many2one vers l’enregistrement lié (utilisé par
_inherits). - backend_id
- Le many2one vers le backend (par exemple
magento.backend). - external_id
- L’ID sur le backend.
- sync_date
- Dernière date de synchronisation
The definition of the field relations is to be done in the concrete classes because the relations themselves do not exist in this addon.
Par exemple, pour un
res.partner.categorydepuis Magento, J’aurais (ceci est une consolidation de toutes les colonnes des modèles abstraits. Dansmagentoerpconnectvous ne trouveriez pas ça)class MagentoResPartnerCategory(models.Model): _name = 'magento.res.partner.category' _inherits = {'res.partner.category': 'odoo_id'} odoo_id = fields.Many2one(comodel_name='res.partner.category', string='Partner Category', required=True, ondelete='cascade') backend_id = fields.Many2one( comodel_name='magento.backend', string='Magento Backend', required=True, ondelete='restrict') external_id = fields.Char(string='ID on Magento') tax_class_id = fields.Integer(string='Tax Class ID') _sql_constraints = [ ('magento_uniq', 'unique(backend_id, magento_id)', 'Partner Tag with same ID on Magento already exists.'), ]