Modèles¶
Backend Model¶
-
class
connector.backend_model.
ConnectorBackend
(pool, cr)[source]¶ Bases :
odoo.models.BaseModel
Une instance d’un backend externe auquel se synchroniser
Les backends doivent
_inherit
ce 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 magentoerpconnect/magento_model.py class MagentoBackend(models.Model): _name = 'magento.backend' _description = 'Magento Backend' _inherit = 'connector.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')] version = fields.Selection( selection='_select_versions', string='Version', required=True, ) location = fields.Char(string='Location', required=True) username = fields.Char(string='Username') password = fields.Char(string='Password')
-
name
¶ Basic string field, can be length-limited, usually displayed as a single-line string in clients.
Paramètres: - size (int) – la taille maximum des valeurs stockées dans ce champ
- translate – enable the translation of the field’s values; use
translate=True
to translate field values as a whole;translate
may also be a callable such thattranslate(callback, value)
translatesvalue
by usingcallback(term)
to retrieve the translation of terms.
-
version
¶ Paramètres: - selection – specifies the possible values for this field.
It is given as either a list of pairs (
value
,string
), or a model method, or a method name. - selection_add – provides an extension of the selection in the case
of an overridden field. It is a list of pairs (
value
,string
).
The attribute
selection
is mandatory except in the case of related fields or field extensions.- selection – specifies the possible values for this field.
It is given as either a list of pairs (
-
Binding Model¶
-
class
connector.backend_model.
ExternalBinding
(pool, cr)[source]¶ Bases :
odoo.models.BaseModel
Un 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.partner
ou pour un article,magento.product
.Le modèle final sera un
_inherits
du modèle Odoo et va_inherit
ce 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.category
depuis Magento, J’aurais (ceci est une consolidation de toutes les colonnes des modèles abstraits. Dansmagentoerpconnect
vous 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.'), ]