Skip to content

Commit ca5916d

Browse files
committed
Merge pull request #47 from guewen/8.0-connector-new-api
New API in connector, bump to 3.0.0
2 parents 3275c8b + 8cd17cb commit ca5916d

29 files changed

+1625
-996
lines changed

.coveragerc

-15
This file was deleted.

connector/CHANGES.rst

+68
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,74 @@
11
Changelog
22
---------
33

4+
3.0.0 (not released)
5+
~~~~~~~~~~~~~~~~~~~~
6+
7+
/!\ Backwards incompatible changes inside.
8+
9+
* Add ``openerp.api.Environment`` in ``Session``
10+
It is accessible in ``self.env`` in ``Session`` and all
11+
``ConnectorUnit`` instances.
12+
Also in ``ConnectorUnit``, ``model`` returns the current (new api!) model:
13+
14+
.. code-block:: python
15+
16+
# On the current model
17+
self.model.search([])
18+
self.model.browse(ids)
19+
# on another model
20+
self.env['res.users'].search([])
21+
self.env['res.users'].browse(ids)
22+
23+
* Deprecate the CRUD methods in ``Session``
24+
25+
.. code-block:: python
26+
27+
# NO
28+
self.session.search('res.partner', [])
29+
self.session.browse('res.partner', ids)
30+
31+
# YES
32+
self.env['res.partner'].search([])
33+
self.env['res.partner'].browse(ids)
34+
35+
* ``Environment.set_lang()`` is removed. It was modifying the context
36+
in place which is not possible with the new frozendict context. It
37+
should be done with:
38+
39+
.. code-block:: python
40+
41+
with self.session.change_context(lang=lang_code):
42+
...
43+
44+
* Add an argument on the Binders methods to return a browse record
45+
46+
.. code-block:: python
47+
48+
binder.to_openerp(magento_id, browse=True)
49+
50+
* Shorten ``ConnectorUnit.get_binder_for_model`` to
51+
``ConnectorUnit.binder_for``
52+
* Shorten ``ConnectorUnit.get_connector_unit_for_model`` to
53+
``ConnectorUnit.unit_for``
54+
* Renamed ``Environment`` to ``ConnectorEnvironment`` to avoid
55+
confusion with ``openerp.api.Environment``
56+
* Renamed the class attribute ``ConnectorUnit.model_name`` to
57+
``ConnectorUnit.for_model_name``.
58+
* Added ``_base_binder``, ``_base_mapper``, ``_base_backend_adapter`` in
59+
the synchronizers (Importer, Exporter) so it is no longer required to
60+
override the ``binder``, ``mapper``, ``backend_adapter`` property
61+
methods
62+
* ``Session.change_context()`` now supports the same
63+
argument/keyword arguments semantics than
64+
``openerp.model.BaseModel.with_context()``.
65+
* Renamed ``ExportSynchronizer`` to ``Exporter``
66+
* Renamed ``ImportSynchronizer`` to ``Importer``
67+
* Renamed ``DeleteSynchronizer`` to ``Deleter``
68+
* ``Session.commit`` do not commit when tests are running
69+
* Cleaned the methods that have been deprecated in version 2.x
70+
71+
472
2.2.0 (2014-05-26)
573
~~~~~~~~~~~~~~~~~~
674

connector/README.rst

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:alt: License
3+
4+
Connector
5+
=========
6+
7+
This is a framework designed to build connectors with external systems,
8+
usually called `Backends` in the documentation.
9+
10+
Documentation: http://odoo-connector.com
11+
12+
It features:
13+
14+
* A jobs queue
15+
16+
In which the connectors can push functions (synchronization tasks)
17+
to be executed later.
18+
19+
* An event pattern
20+
21+
The connectors can subscribe listener functions on the events,
22+
executed when the events are fired.
23+
24+
* Connector base classes
25+
26+
Called ``ConnectorUnit``.
27+
28+
Include base classes for the use in connectors, ready to be extended:
29+
30+
* ``Synchronizer``: flow of an import or export
31+
* ``Mapper``: transform a record according to mapping rules
32+
* ``Binder``: link external IDs with local IDS
33+
* ``BackendAdapter``: adapter interface for the exchanges with the backend
34+
* But ``ConnectorUnit`` can be extended to accomplish any task
35+
36+
* A multi-backend support
37+
38+
Each ``ConnectorUnit`` can be registered amongst a backend type (eg.
39+
Magento) and a backend version (allow to have a different ``Mapper``
40+
for each backend's version for instance)
41+
42+
It is used for example used to connect Magento_ and Prestashop_, but
43+
also used with Solr, CMIS, ...
44+
45+
.. _Magento: http://odoo-magento-connector.com
46+
.. _Prestashop: https://github.com/OCA/connector-prestashop
47+
48+
Configuration and usage
49+
=======================
50+
51+
This module does nothing on its own. It is a ground for developing
52+
advanced connector modules. For further information, please go on:
53+
http://odoo-connector.com
54+
55+
Credits
56+
=======
57+
58+
Contributors
59+
------------
60+
61+
Read the `contributors list`_
62+
63+
.. _contributors list: ./AUTHORS
64+
65+
Maintainer
66+
----------
67+
68+
.. image:: http://odoo-community.org/logo.png
69+
:alt: Odoo Community Association
70+
:target: http://odoo-community.org
71+
72+
This module is maintained by the OCA.
73+
74+
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.
75+
76+
To contribute to this module, please visit http://odoo-community.org.

connector/__openerp__.py

+3-44
Original file line numberDiff line numberDiff line change
@@ -20,53 +20,12 @@
2020
##############################################################################
2121

2222
{'name': 'Connector',
23-
'version': '2.2.0',
24-
'author': "Openerp Connector Core Editors,Odoo Community Association (OCA)",
23+
'version': '3.0.0',
24+
'author': 'Camptocamp,Openerp Connector Core Editors,'
25+
'Odoo Community Association (OCA)',
2526
'website': 'http://odoo-connector.com',
2627
'license': 'AGPL-3',
2728
'category': 'Generic Modules',
28-
'description': """
29-
Connector
30-
=========
31-
32-
This is a framework designed to build connectors with external systems,
33-
usually called `Backends`.
34-
35-
Documentation: http://odoo-connector.com
36-
37-
It features:
38-
39-
* A jobs queue
40-
41-
In which the connectors can push functions (synchronization tasks)
42-
to be executed later.
43-
44-
* An event pattern
45-
46-
The connectors can subscribe consumer methods, executed when the events
47-
are fired.
48-
49-
* Connector base classes
50-
51-
Called ``ConnectorUnit``.
52-
53-
Include base classes for the use in connectors, ready to be extended:
54-
55-
* ``Synchronizer``: flow of an import or export
56-
* ``Mapper``: transform a record according to mapping rules
57-
* ``Binder``: link external IDs with local IDS
58-
* ``BackendAdapter``: adapter interface for the exchanges with the backend
59-
60-
* A multi-backend support
61-
62-
Each ``ConnectorUnit`` can be registered amongst a backend type (eg.
63-
Magento) or a backend version only.
64-
65-
It is actually used to connect Magento_ and Prestashop_
66-
67-
.. _Magento: http://odoo-magento-connector.com
68-
.. _Prestashop: https://launchpad.net/prestashoperpconnect
69-
""",
7029
'depends': ['mail'
7130
],
7231
'data': ['security/connector_security.xml',

connector/backend.py

+3-20
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,8 @@ class Synchronizer1700(Synchronizer):
165165
is able to extend or replace the behavior of its parent.
166166
167167
.. note:: when using the framework, you won't need to call
168-
:py:meth:`~get_class`, usually, you will call
169-
:py:meth:`connector.connector.Environment.get_connector_unit`.
168+
:py:meth:`~get_class`, usually, you will call
169+
:py:meth:`connector.connector.ConnectorEnvironment.get_connector_unit`.
170170
171171
The vertical extension is the one you will probably use the most, because
172172
most of the things you will change concern your custom adaptations or
@@ -219,7 +219,7 @@ def service(self):
219219
def __str__(self):
220220
if self.version:
221221
return 'Backend(\'%s\', \'%s\')' % (self.service, self.version)
222-
return 'Backend(\'%s\')>' % self.service
222+
return 'Backend(\'%s\')' % self.service
223223

224224
def __repr__(self):
225225
if self.version:
@@ -306,23 +306,6 @@ def register_replace(replacing_cls):
306306
register_replace(replacing)
307307
self._class_entries.append(entry)
308308

309-
def unregister_class(self, cls):
310-
""" Deprecated. Was used to remove a ``ConnectorUnit``
311-
from the registry. Now, the ``replacing`` argument of
312-
the decorator or ``register_clas()`` should be used.
313-
314-
It has been deprecated because it is not safe to unregister
315-
a ConnectorUnit due to the way OpenERP works with addons.
316-
A python module can be imported even if a addon is not installed.
317-
"""
318-
raise DeprecationWarning('Backend.unregister_class() is deprecated. '
319-
'You have to use the replacing argument '
320-
'of the register_class() method')
321-
322-
def registered_classes(self, base_class=None):
323-
""" Deprecated. """
324-
raise DeprecationWarning('Backend.registered_classes() is deprecated.')
325-
326309
def __call__(self, cls=None, replacing=None):
327310
""" Backend decorator
328311

connector/backend_model.py

+24-36
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#
2020
##############################################################################
2121

22-
from openerp.osv import orm, fields
22+
from openerp import models, fields, api
2323
from . import backend
2424

2525

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

36-
_columns = {
37-
'name': fields.char('Name', required=True),
38-
# replace by a selection in concrete models
39-
'version': fields.selection((), 'Version', required=True),
40-
}
36+
name = fields.Char(required=True)
37+
# replace by a selection in concrete models
38+
version = fields.Selection(selection=[], required=True)
4139

42-
def get_backend(self, cr, uid, ids, context=None):
40+
@api.multi
41+
def get_backend(self):
4342
""" For a record of backend, returns the appropriate instance
4443
of :py:class:`~connector.backend.Backend`.
4544
"""
46-
if hasattr(ids, '__iter__'):
47-
assert len(ids) == 1, "One ID expected, %d received" % len(ids)
48-
ids = ids[0]
45+
self.ensure_one()
4946
if self._backend_type is None:
5047
raise ValueError('The backend %s has no _backend_type' % self)
51-
backend_record = self.browse(cr, uid, ids, context=context)
52-
return backend.get_backend(self._backend_type, backend_record.version)
48+
return backend.get_backend(self._backend_type, self.version)
5349

5450

55-
class external_binding(orm.AbstractModel):
51+
class ExternalBinding(models.AbstractModel):
5652
""" An abstract model for bindings to external records.
5753
5854
An external binding is a binding between a backend and OpenERP. For
@@ -95,25 +91,22 @@ class external_binding(orm.AbstractModel):
9591
(this is a consolidation of all the columns from the abstract models,
9692
in ``magentoerpconnect`` you would not find that)::
9793
98-
class magento_res_partner_category(orm.Model):
94+
class MagentoResPartnerCategory(models.Model):
9995
_name = 'magento.res.partner.category'
10096
10197
_inherits = {'res.partner.category': 'openerp_id'}
10298
103-
_columns = {
104-
'openerp_id': fields.many2one('res.partner.category',
105-
string='Partner Category',
106-
required=True,
107-
ondelete='cascade'),
108-
'backend_id': fields.many2one(
109-
'magento.backend',
110-
'Magento Backend',
111-
required=True,
112-
ondelete='restrict'),
113-
'sync_date': fields.datetime('Last synchronization date'),
114-
'magento_id': fields.char('ID on Magento'),
115-
'tax_class_id': fields.integer('Tax Class ID'),
116-
}
99+
openerp_id = fields.Many2one(comodel_name='res.partner.category',
100+
string='Partner Category',
101+
required=True,
102+
ondelete='cascade')
103+
backend_id = fields.Many2one(
104+
comodel_name='magento.backend',
105+
string='Magento Backend',
106+
required=True,
107+
ondelete='restrict')
108+
magento_id = fields.Char(string='ID on Magento')
109+
tax_class_id = fields.Integer(string='Tax Class ID')
117110
118111
_sql_constraints = [
119112
('magento_uniq', 'unique(backend_id, magento_id)',
@@ -125,10 +118,5 @@ class magento_res_partner_category(orm.Model):
125118
_name = 'external.binding'
126119
_description = 'External Binding (abstract)'
127120

128-
_columns = {
129-
# TODO write the date on import / export
130-
# and skip import / export (avoid unnecessary import
131-
# right after the export)
132-
'sync_date': fields.datetime('Last synchronization date'),
133-
# add other fields in concrete models
134-
}
121+
sync_date = fields.Datetime(string='Last synchronization date')
122+
# add other fields in concrete models

0 commit comments

Comments
 (0)