Skip to content

Commit 1f1f320

Browse files
committed
[MIG] connector_magento: Migration to 13.0
1 parent d9515f3 commit 1f1f320

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+3045
-2715
lines changed

connector_magento/__manifest__.py

+43-41
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,46 @@
22
# © 2016 Sodexis
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5-
{'name': 'Magento Connector',
6-
'version': '12.0.1.1.4',
7-
'category': 'Connector',
8-
'depends': ['account',
9-
'base_technical_user',
10-
'product',
11-
'delivery',
12-
'sale_stock',
13-
'product_multi_category',
14-
'connector_ecommerce',
15-
],
16-
'external_dependencies': {
17-
'python': ['magento'],
18-
},
19-
'author': "Camptocamp,Akretion,Sodexis,Odoo Community Association (OCA)",
20-
'license': 'AGPL-3',
21-
'website': 'http://www.odoo-magento-connector.com',
22-
'images': ['images/magento_backend.png',
23-
'images/jobs.png',
24-
'images/product_binding.png',
25-
'images/invoice_binding.png',
26-
'images/connector_magento.png',
27-
],
28-
'data': ['data/connector_magento_data.xml',
29-
'data/res_partner_category.xml',
30-
'security/ir.model.access.csv',
31-
'views/magento_backend_views.xml',
32-
'views/product_views.xml',
33-
'views/product_category_views.xml',
34-
'views/partner_views.xml',
35-
'views/invoice_views.xml',
36-
'views/sale_order_views.xml',
37-
'views/connector_magento_menu.xml',
38-
'views/delivery_views.xml',
39-
'views/stock_views.xml',
40-
'views/account_payment_mode_views.xml',
41-
'wizards/magento_binding_backend_read.xml',
42-
],
43-
'installable': True,
44-
'application': False,
45-
}
5+
{
6+
"name": "Magento Connector",
7+
"version": "13.0.0.0.0",
8+
"category": "Connector",
9+
"depends": [
10+
"account",
11+
"base_technical_user",
12+
"product",
13+
"delivery",
14+
"sale_stock",
15+
"product_multi_category",
16+
"connector_ecommerce",
17+
],
18+
"external_dependencies": {"python": ["magento"]},
19+
"author": "Camptocamp,Akretion,Sodexis,Odoo Community Association (OCA)",
20+
"license": "AGPL-3",
21+
"website": "http://www.odoo-magento-connector.com",
22+
"images": [
23+
"images/magento_backend.png",
24+
"images/jobs.png",
25+
"images/product_binding.png",
26+
"images/invoice_binding.png",
27+
"images/connector_magento.png",
28+
],
29+
"data": [
30+
"data/connector_magento_data.xml",
31+
"data/res_partner_category.xml",
32+
"security/ir.model.access.csv",
33+
"views/magento_backend_views.xml",
34+
"views/product_views.xml",
35+
"views/product_category_views.xml",
36+
"views/partner_views.xml",
37+
"views/invoice_views.xml",
38+
"views/sale_order_views.xml",
39+
"views/connector_magento_menu.xml",
40+
"views/delivery_views.xml",
41+
"views/stock_views.xml",
42+
"views/account_payment_mode_views.xml",
43+
"wizards/magento_binding_backend_read.xml",
44+
],
45+
"installable": True,
46+
"application": False,
47+
}

connector_magento/components/backend_adapter.py

+13-10
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ def location(self):
5353
if not self.use_auth_basic:
5454
return location
5555
assert self.auth_basic_username and self.auth_basic_password
56-
replacement = "{}:{}@".format(self.auth_basic_username, self.auth_basic_password)
56+
replacement = "{}:{}@".format(
57+
self.auth_basic_username, self.auth_basic_password
58+
)
5759
location = location.replace("://", "://" + replacement)
5860
return location
5961

@@ -198,16 +200,16 @@ class MagentoCRUDAdapter(AbstractComponent):
198200
_usage = "backend.adapter"
199201

200202
def search(self, filters=None):
201-
""" Search records according to some criterias
202-
and returns a list of ids """
203+
"""Search records according to some criterias
204+
and returns a list of ids"""
203205
raise NotImplementedError
204206

205207
def read(self, external_id, attributes=None, storeview=None):
206208
""" Returns the information of a record """
207209
raise NotImplementedError
208210

209211
def search_read(self, filters=None):
210-
""" Search records according to some criterias
212+
"""Search records according to some criterias
211213
and returns their information"""
212214
raise NotImplementedError
213215

@@ -225,7 +227,7 @@ def delete(self, external_id):
225227

226228
def _call(self, method, arguments=None, http_method=None, storeview=None):
227229
try:
228-
magento_api = getattr(self.work, "magento_api")
230+
magento_api = getattr(self.work, "magento_api") # noqa: B009
229231
except AttributeError:
230232
raise AttributeError(
231233
"You must provide a magento_api attribute with a "
@@ -252,7 +254,7 @@ class GenericAdapter(AbstractComponent):
252254

253255
@staticmethod
254256
def get_searchCriteria(filters):
255-
""" Craft Magento 2.0 searchCriteria from filters, for example:
257+
"""Craft Magento 2.0 searchCriteria from filters, for example:
256258
'searchCriteria[filter_groups][0][filters][0][field]': 'website_id',
257259
'searchCriteria[filter_groups][0][filters][0][value]': '1,2',
258260
'searchCriteria[filter_groups][0][filters][0][condition_type]': 'in',
@@ -301,7 +303,7 @@ def get_searchCriteria(filters):
301303
return res if res else {"searchCriteria": ""}
302304

303305
def search(self, filters=None):
304-
""" Search records according to some criterias
306+
"""Search records according to some criterias
305307
and returns a list of unique identifiers
306308
307309
In the case of Magento 2.x: query the resource to return the key field
@@ -339,7 +341,7 @@ def escape(term):
339341
return term
340342

341343
def read(self, external_id, attributes=None, storeview=None):
342-
""" Returns the information of a record
344+
"""Returns the information of a record
343345
344346
:rtype: dict
345347
"""
@@ -371,7 +373,7 @@ def read(self, external_id, attributes=None, storeview=None):
371373
return next(record for record in res if record["id"] == external_id)
372374

373375
def search_read(self, filters=None):
374-
""" Search records according to some criterias
376+
"""Search records according to some criterias
375377
and returns their information"""
376378
if self.collection.version == "1.7":
377379
return self._call("%s.list" % self._magento_model, [filters])
@@ -410,7 +412,8 @@ def admin_url(self, external_id):
410412
if not url:
411413
raise ValueError("No admin URL configured on the backend.")
412414
if hasattr(self.model, "_get_admin_path"):
413-
admin_path = getattr(self.model, "_get_admin_path")(backend, external_id)
415+
admin_func = getattr(self.model, "_get_admin_path") # noqa: B009
416+
admin_path = admin_func(backend, external_id)
414417
else:
415418
key = "_admin2_path" if backend.version == "2.0" else "_admin_path"
416419
admin_path = getattr(self, key)

connector_magento/components/binder.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ class MagentoModelBinder(Component):
2929
"magento.stock.picking",
3030
"magento.sale.order",
3131
"magento.sale.order.line",
32-
"magento.account.invoice",
32+
"magento.account.move",
3333
]

connector_magento/components/exporter.py

+20-21
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@
22
# © 2016 Sodexis
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5+
"""
6+
7+
Exporters for Magento.
8+
9+
In addition to its export job, an exporter has to:
10+
11+
* check in Magento if the record has been updated more recently than the
12+
last sync date and if yes, delay an import
13+
* call the ``bind`` method of the binder to update the last sync date
14+
15+
"""
16+
517
import logging
618
from contextlib import contextmanager
719
from datetime import datetime
@@ -19,19 +31,6 @@
1931
_logger = logging.getLogger(__name__)
2032

2133

22-
"""
23-
24-
Exporters for Magento.
25-
26-
In addition to its export job, an exporter has to:
27-
28-
* check in Magento if the record has been updated more recently than the
29-
last sync date and if yes, delay an import
30-
* call the ``bind`` method of the binder to update the last sync date
31-
32-
"""
33-
34-
3534
class MagentoBaseExporter(AbstractComponent):
3635
""" Base exporter for Magento """
3736

@@ -45,7 +44,7 @@ def __init__(self, working_context):
4544
self.external_id = None
4645

4746
def _delay_import(self):
48-
""" Schedule an import of the record.
47+
"""Schedule an import of the record.
4948
5049
Adapt in the sub-classes when the model is not imported
5150
using ``import_record``.
@@ -58,7 +57,7 @@ def _delay_import(self):
5857
)
5958

6059
def _should_import(self):
61-
""" Before the export, compare the update date
60+
"""Before the export, compare the update date
6261
in Magento and the last sync date in Odoo,
6362
if the former is more recent, schedule an import
6463
to not miss changes done in Magento.
@@ -78,7 +77,7 @@ def _should_import(self):
7877
return sync_date < magento_date
7978

8079
def run(self, binding, *args, **kwargs):
81-
""" Run the synchronization
80+
"""Run the synchronization
8281
8382
:param binding: binding record to export
8483
"""
@@ -127,7 +126,7 @@ def __init__(self, working_context):
127126
self.binding = None
128127

129128
def _lock(self):
130-
""" Lock the binding record.
129+
"""Lock the binding record.
131130
132131
Lock the binding record so we are sure that only one export
133132
job is running for this record if concurrent jobs have to export the
@@ -164,7 +163,7 @@ def _has_to_skip(self):
164163

165164
@contextmanager
166165
def _retry_unique_violation(self):
167-
""" Context manager: catch Unique constraint error and retry the
166+
"""Context manager: catch Unique constraint error and retry the
168167
job later.
169168
170169
When we execute several jobs workers concurrently, it happens
@@ -302,14 +301,14 @@ def _export_dependencies(self):
302301
return
303302

304303
def _map_data(self):
305-
""" Returns an instance of
304+
"""Returns an instance of
306305
:py:class:`~odoo.addons.connector.components.mapper.MapRecord`
307306
308307
"""
309308
return self.mapper.map_record(self.binding)
310309

311310
def _validate_create_data(self, data):
312-
""" Check if the values to import are correct
311+
"""Check if the values to import are correct
313312
314313
Pro-actively check before the ``Model.create`` if some fields
315314
are missing or invalid
@@ -319,7 +318,7 @@ def _validate_create_data(self, data):
319318
return
320319

321320
def _validate_update_data(self, data):
322-
""" Check if the values to import are correct
321+
"""Check if the values to import are correct
323322
324323
Pro-actively check before the ``Model.update`` if some fields
325324
are missing or invalid

connector_magento/components/importer.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ def run(self, external_id, binding, mapper=None):
317317
)
318318
if not storeviews:
319319
return
320-
lang2storeview = {
321-
storeview.lang_id: storeview for storeview in storeviews
322-
}
320+
lang2storeview = {storeview.lang_id: storeview for storeview in storeviews}
323321

324322
# find the translatable fields of the model
325323
fields = self.model.fields_get()

connector_magento/doc/api/api_models.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,13 @@ Synchronized Models
113113
Invoice
114114
=======
115115

116-
.. automodule:: odoo.addons.connector_magento.models.account_invoice.common
116+
.. automodule:: odoo.addons.connector_magento.models.account_move.common
117117
:show-inheritance:
118118
:private-members:
119119
.. :members:
120120
:undoc-members:
121121
122-
.. automodule:: odoo.addons.connector_magento.models.account_invoice.exporter
122+
.. automodule:: odoo.addons.connector_magento.models.account_move.exporter
123123
:members:
124124
:undoc-members:
125125
:show-inheritance:

connector_magento/exception.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# © 2016 Sodexis
33
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
44

5-
from openerp.addons.connector.exception import RetryableJobError
5+
from odoo.addons.connector.exception import RetryableJobError
66

77

88
class OrderImportRuleRetry(RetryableJobError):

0 commit comments

Comments
 (0)