Skip to content

Commit

Permalink
Merge pull request #47 from guewen/8.0-connector-new-api
Browse files Browse the repository at this point in the history
New API in connector, bump to 3.0.0
  • Loading branch information
pedrobaeza committed Apr 1, 2015
2 parents 3275c8b + 8cd17cb commit ca5916d
Show file tree
Hide file tree
Showing 29 changed files with 1,625 additions and 996 deletions.
15 changes: 0 additions & 15 deletions .coveragerc

This file was deleted.

68 changes: 68 additions & 0 deletions connector/CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,74 @@
Changelog
---------

3.0.0 (not released)
~~~~~~~~~~~~~~~~~~~~

/!\ Backwards incompatible changes inside.

* Add ``openerp.api.Environment`` in ``Session``
It is accessible in ``self.env`` in ``Session`` and all
``ConnectorUnit`` instances.
Also in ``ConnectorUnit``, ``model`` returns the current (new api!) model:

.. code-block:: python
# On the current model
self.model.search([])
self.model.browse(ids)
# on another model
self.env['res.users'].search([])
self.env['res.users'].browse(ids)
* Deprecate the CRUD methods in ``Session``

.. code-block:: python
# NO
self.session.search('res.partner', [])
self.session.browse('res.partner', ids)
# YES
self.env['res.partner'].search([])
self.env['res.partner'].browse(ids)
* ``Environment.set_lang()`` is removed. It was modifying the context
in place which is not possible with the new frozendict context. It
should be done with:

.. code-block:: python
with self.session.change_context(lang=lang_code):
...
* Add an argument on the Binders methods to return a browse record

.. code-block:: python
binder.to_openerp(magento_id, browse=True)
* Shorten ``ConnectorUnit.get_binder_for_model`` to
``ConnectorUnit.binder_for``
* Shorten ``ConnectorUnit.get_connector_unit_for_model`` to
``ConnectorUnit.unit_for``
* Renamed ``Environment`` to ``ConnectorEnvironment`` to avoid
confusion with ``openerp.api.Environment``
* Renamed the class attribute ``ConnectorUnit.model_name`` to
``ConnectorUnit.for_model_name``.
* Added ``_base_binder``, ``_base_mapper``, ``_base_backend_adapter`` in
the synchronizers (Importer, Exporter) so it is no longer required to
override the ``binder``, ``mapper``, ``backend_adapter`` property
methods
* ``Session.change_context()`` now supports the same
argument/keyword arguments semantics than
``openerp.model.BaseModel.with_context()``.
* Renamed ``ExportSynchronizer`` to ``Exporter``
* Renamed ``ImportSynchronizer`` to ``Importer``
* Renamed ``DeleteSynchronizer`` to ``Deleter``
* ``Session.commit`` do not commit when tests are running
* Cleaned the methods that have been deprecated in version 2.x


2.2.0 (2014-05-26)
~~~~~~~~~~~~~~~~~~

Expand Down
76 changes: 76 additions & 0 deletions connector/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:alt: License

Connector
=========

This is a framework designed to build connectors with external systems,
usually called `Backends` in the documentation.

Documentation: http://odoo-connector.com

It features:

* A jobs queue

In which the connectors can push functions (synchronization tasks)
to be executed later.

* An event pattern

The connectors can subscribe listener functions on the events,
executed when the events are fired.

* Connector base classes

Called ``ConnectorUnit``.

Include base classes for the use in connectors, ready to be extended:

* ``Synchronizer``: flow of an import or export
* ``Mapper``: transform a record according to mapping rules
* ``Binder``: link external IDs with local IDS
* ``BackendAdapter``: adapter interface for the exchanges with the backend
* But ``ConnectorUnit`` can be extended to accomplish any task

* A multi-backend support

Each ``ConnectorUnit`` can be registered amongst a backend type (eg.
Magento) and a backend version (allow to have a different ``Mapper``
for each backend's version for instance)

It is used for example used to connect Magento_ and Prestashop_, but
also used with Solr, CMIS, ...

.. _Magento: http://odoo-magento-connector.com
.. _Prestashop: https://github.com/OCA/connector-prestashop

Configuration and usage
=======================

This module does nothing on its own. It is a ground for developing
advanced connector modules. For further information, please go on:
http://odoo-connector.com

Credits
=======

Contributors
------------

Read the `contributors list`_

.. _contributors list: ./AUTHORS

Maintainer
----------

.. image:: http://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: http://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.

To contribute to this module, please visit http://odoo-community.org.
47 changes: 3 additions & 44 deletions connector/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,53 +20,12 @@
##############################################################################

{'name': 'Connector',
'version': '2.2.0',
'author': "Openerp Connector Core Editors,Odoo Community Association (OCA)",
'version': '3.0.0',
'author': 'Camptocamp,Openerp Connector Core Editors,'
'Odoo Community Association (OCA)',
'website': 'http://odoo-connector.com',
'license': 'AGPL-3',
'category': 'Generic Modules',
'description': """
Connector
=========
This is a framework designed to build connectors with external systems,
usually called `Backends`.
Documentation: http://odoo-connector.com
It features:
* A jobs queue
In which the connectors can push functions (synchronization tasks)
to be executed later.
* An event pattern
The connectors can subscribe consumer methods, executed when the events
are fired.
* Connector base classes
Called ``ConnectorUnit``.
Include base classes for the use in connectors, ready to be extended:
* ``Synchronizer``: flow of an import or export
* ``Mapper``: transform a record according to mapping rules
* ``Binder``: link external IDs with local IDS
* ``BackendAdapter``: adapter interface for the exchanges with the backend
* A multi-backend support
Each ``ConnectorUnit`` can be registered amongst a backend type (eg.
Magento) or a backend version only.
It is actually used to connect Magento_ and Prestashop_
.. _Magento: http://odoo-magento-connector.com
.. _Prestashop: https://launchpad.net/prestashoperpconnect
""",
'depends': ['mail'
],
'data': ['security/connector_security.xml',
Expand Down
23 changes: 3 additions & 20 deletions connector/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ class Synchronizer1700(Synchronizer):
is able to extend or replace the behavior of its parent.
.. note:: when using the framework, you won't need to call
:py:meth:`~get_class`, usually, you will call
:py:meth:`connector.connector.Environment.get_connector_unit`.
:py:meth:`~get_class`, usually, you will call
:py:meth:`connector.connector.ConnectorEnvironment.get_connector_unit`.
The vertical extension is the one you will probably use the most, because
most of the things you will change concern your custom adaptations or
Expand Down Expand Up @@ -219,7 +219,7 @@ def service(self):
def __str__(self):
if self.version:
return 'Backend(\'%s\', \'%s\')' % (self.service, self.version)
return 'Backend(\'%s\')>' % self.service
return 'Backend(\'%s\')' % self.service

def __repr__(self):
if self.version:
Expand Down Expand Up @@ -306,23 +306,6 @@ def register_replace(replacing_cls):
register_replace(replacing)
self._class_entries.append(entry)

def unregister_class(self, cls):
""" Deprecated. Was used to remove a ``ConnectorUnit``
from the registry. Now, the ``replacing`` argument of
the decorator or ``register_clas()`` should be used.
It has been deprecated because it is not safe to unregister
a ConnectorUnit due to the way OpenERP works with addons.
A python module can be imported even if a addon is not installed.
"""
raise DeprecationWarning('Backend.unregister_class() is deprecated. '
'You have to use the replacing argument '
'of the register_class() method')

def registered_classes(self, base_class=None):
""" Deprecated. """
raise DeprecationWarning('Backend.registered_classes() is deprecated.')

def __call__(self, cls=None, replacing=None):
""" Backend decorator
Expand Down
60 changes: 24 additions & 36 deletions connector/backend_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#
##############################################################################

from openerp.osv import orm, fields
from openerp import models, fields, api
from . import backend


class connector_backend(orm.AbstractModel):
class ConnectorBackend(models.AbstractModel):
""" An instance of an external backend to synchronize with.
The backends have to ``_inherit`` this model in the connectors
Expand All @@ -33,26 +33,22 @@ class connector_backend(orm.AbstractModel):
_description = 'Connector Backend'
_backend_type = None

_columns = {
'name': fields.char('Name', required=True),
# replace by a selection in concrete models
'version': fields.selection((), 'Version', required=True),
}
name = fields.Char(required=True)
# replace by a selection in concrete models
version = fields.Selection(selection=[], required=True)

def get_backend(self, cr, uid, ids, context=None):
@api.multi
def get_backend(self):
""" For a record of backend, returns the appropriate instance
of :py:class:`~connector.backend.Backend`.
"""
if hasattr(ids, '__iter__'):
assert len(ids) == 1, "One ID expected, %d received" % len(ids)
ids = ids[0]
self.ensure_one()
if self._backend_type is None:
raise ValueError('The backend %s has no _backend_type' % self)
backend_record = self.browse(cr, uid, ids, context=context)
return backend.get_backend(self._backend_type, backend_record.version)
return backend.get_backend(self._backend_type, self.version)


class external_binding(orm.AbstractModel):
class ExternalBinding(models.AbstractModel):
""" An abstract model for bindings to external records.
An external binding is a binding between a backend and OpenERP. For
Expand Down Expand Up @@ -95,25 +91,22 @@ class external_binding(orm.AbstractModel):
(this is a consolidation of all the columns from the abstract models,
in ``magentoerpconnect`` you would not find that)::
class magento_res_partner_category(orm.Model):
class MagentoResPartnerCategory(models.Model):
_name = 'magento.res.partner.category'
_inherits = {'res.partner.category': 'openerp_id'}
_columns = {
'openerp_id': fields.many2one('res.partner.category',
string='Partner Category',
required=True,
ondelete='cascade'),
'backend_id': fields.many2one(
'magento.backend',
'Magento Backend',
required=True,
ondelete='restrict'),
'sync_date': fields.datetime('Last synchronization date'),
'magento_id': fields.char('ID on Magento'),
'tax_class_id': fields.integer('Tax Class ID'),
}
openerp_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')
magento_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)',
Expand All @@ -125,10 +118,5 @@ class magento_res_partner_category(orm.Model):
_name = 'external.binding'
_description = 'External Binding (abstract)'

_columns = {
# TODO write the date on import / export
# and skip import / export (avoid unnecessary import
# right after the export)
'sync_date': fields.datetime('Last synchronization date'),
# add other fields in concrete models
}
sync_date = fields.Datetime(string='Last synchronization date')
# add other fields in concrete models
Loading

0 comments on commit ca5916d

Please sign in to comment.