Skip to content

Commit

Permalink
[MIG] connector_magento: Migration to 13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev authored and dreispt committed Apr 27, 2024
1 parent dc24ef1 commit f53584b
Show file tree
Hide file tree
Showing 59 changed files with 3,045 additions and 2,715 deletions.
84 changes: 43 additions & 41 deletions connector_magento/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,46 @@
# © 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{'name': 'Magento Connector',
'version': '12.0.1.1.4',
'category': 'Connector',
'depends': ['account',
'base_technical_user',
'product',
'delivery',
'sale_stock',
'product_multi_category',
'connector_ecommerce',
],
'external_dependencies': {
'python': ['magento'],
},
'author': "Camptocamp,Akretion,Sodexis,Odoo Community Association (OCA)",
'license': 'AGPL-3',
'website': 'http://www.odoo-magento-connector.com',
'images': ['images/magento_backend.png',
'images/jobs.png',
'images/product_binding.png',
'images/invoice_binding.png',
'images/connector_magento.png',
],
'data': ['data/connector_magento_data.xml',
'data/res_partner_category.xml',
'security/ir.model.access.csv',
'views/magento_backend_views.xml',
'views/product_views.xml',
'views/product_category_views.xml',
'views/partner_views.xml',
'views/invoice_views.xml',
'views/sale_order_views.xml',
'views/connector_magento_menu.xml',
'views/delivery_views.xml',
'views/stock_views.xml',
'views/account_payment_mode_views.xml',
'wizards/magento_binding_backend_read.xml',
],
'installable': True,
'application': False,
}
{
"name": "Magento Connector",
"version": "13.0.0.0.0",
"category": "Connector",
"depends": [
"account",
"base_technical_user",
"product",
"delivery",
"sale_stock",
"product_multi_category",
"connector_ecommerce",
],
"external_dependencies": {"python": ["magento"]},
"author": "Camptocamp,Akretion,Sodexis,Odoo Community Association (OCA)",
"license": "AGPL-3",
"website": "http://www.odoo-magento-connector.com",
"images": [
"images/magento_backend.png",
"images/jobs.png",
"images/product_binding.png",
"images/invoice_binding.png",
"images/connector_magento.png",
],
"data": [
"data/connector_magento_data.xml",
"data/res_partner_category.xml",
"security/ir.model.access.csv",
"views/magento_backend_views.xml",
"views/product_views.xml",
"views/product_category_views.xml",
"views/partner_views.xml",
"views/invoice_views.xml",
"views/sale_order_views.xml",
"views/connector_magento_menu.xml",
"views/delivery_views.xml",
"views/stock_views.xml",
"views/account_payment_mode_views.xml",
"wizards/magento_binding_backend_read.xml",
],
"installable": True,
"application": False,
}
23 changes: 13 additions & 10 deletions connector_magento/components/backend_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ def location(self):
if not self.use_auth_basic:
return location
assert self.auth_basic_username and self.auth_basic_password
replacement = "{}:{}@".format(self.auth_basic_username, self.auth_basic_password)
replacement = "{}:{}@".format(
self.auth_basic_username, self.auth_basic_password
)
location = location.replace("://", "://" + replacement)
return location

Expand Down Expand Up @@ -198,16 +200,16 @@ class MagentoCRUDAdapter(AbstractComponent):
_usage = "backend.adapter"

def search(self, filters=None):
""" Search records according to some criterias
and returns a list of ids """
"""Search records according to some criterias
and returns a list of ids"""
raise NotImplementedError

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

def search_read(self, filters=None):
""" Search records according to some criterias
"""Search records according to some criterias
and returns their information"""
raise NotImplementedError

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

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

@staticmethod
def get_searchCriteria(filters):
""" Craft Magento 2.0 searchCriteria from filters, for example:
"""Craft Magento 2.0 searchCriteria from filters, for example:
'searchCriteria[filter_groups][0][filters][0][field]': 'website_id',
'searchCriteria[filter_groups][0][filters][0][value]': '1,2',
'searchCriteria[filter_groups][0][filters][0][condition_type]': 'in',
Expand Down Expand Up @@ -301,7 +303,7 @@ def get_searchCriteria(filters):
return res if res else {"searchCriteria": ""}

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

def read(self, external_id, attributes=None, storeview=None):
""" Returns the information of a record
"""Returns the information of a record
:rtype: dict
"""
Expand Down Expand Up @@ -371,7 +373,7 @@ def read(self, external_id, attributes=None, storeview=None):
return next(record for record in res if record["id"] == external_id)

def search_read(self, filters=None):
""" Search records according to some criterias
"""Search records according to some criterias
and returns their information"""
if self.collection.version == "1.7":
return self._call("%s.list" % self._magento_model, [filters])
Expand Down Expand Up @@ -410,7 +412,8 @@ def admin_url(self, external_id):
if not url:
raise ValueError("No admin URL configured on the backend.")
if hasattr(self.model, "_get_admin_path"):
admin_path = getattr(self.model, "_get_admin_path")(backend, external_id)
admin_func = getattr(self.model, "_get_admin_path") # noqa: B009
admin_path = admin_func(backend, external_id)
else:
key = "_admin2_path" if backend.version == "2.0" else "_admin_path"
admin_path = getattr(self, key)
Expand Down
2 changes: 1 addition & 1 deletion connector_magento/components/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ class MagentoModelBinder(Component):
"magento.stock.picking",
"magento.sale.order",
"magento.sale.order.line",
"magento.account.invoice",
"magento.account.move",
]
41 changes: 20 additions & 21 deletions connector_magento/components/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
# © 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

"""
Exporters for Magento.
In addition to its export job, an exporter has to:
* check in Magento if the record has been updated more recently than the
last sync date and if yes, delay an import
* call the ``bind`` method of the binder to update the last sync date
"""

import logging
from contextlib import contextmanager
from datetime import datetime
Expand All @@ -19,19 +31,6 @@
_logger = logging.getLogger(__name__)


"""
Exporters for Magento.
In addition to its export job, an exporter has to:
* check in Magento if the record has been updated more recently than the
last sync date and if yes, delay an import
* call the ``bind`` method of the binder to update the last sync date
"""


class MagentoBaseExporter(AbstractComponent):
""" Base exporter for Magento """

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

def _delay_import(self):
""" Schedule an import of the record.
"""Schedule an import of the record.
Adapt in the sub-classes when the model is not imported
using ``import_record``.
Expand All @@ -58,7 +57,7 @@ def _delay_import(self):
)

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

def run(self, binding, *args, **kwargs):
""" Run the synchronization
"""Run the synchronization
:param binding: binding record to export
"""
Expand Down Expand Up @@ -127,7 +126,7 @@ def __init__(self, working_context):
self.binding = None

def _lock(self):
""" Lock the binding record.
"""Lock the binding record.
Lock the binding record so we are sure that only one export
job is running for this record if concurrent jobs have to export the
Expand Down Expand Up @@ -164,7 +163,7 @@ def _has_to_skip(self):

@contextmanager
def _retry_unique_violation(self):
""" Context manager: catch Unique constraint error and retry the
"""Context manager: catch Unique constraint error and retry the
job later.
When we execute several jobs workers concurrently, it happens
Expand Down Expand Up @@ -302,14 +301,14 @@ def _export_dependencies(self):
return

def _map_data(self):
""" Returns an instance of
"""Returns an instance of
:py:class:`~odoo.addons.connector.components.mapper.MapRecord`
"""
return self.mapper.map_record(self.binding)

def _validate_create_data(self, data):
""" Check if the values to import are correct
"""Check if the values to import are correct
Pro-actively check before the ``Model.create`` if some fields
are missing or invalid
Expand All @@ -319,7 +318,7 @@ def _validate_create_data(self, data):
return

def _validate_update_data(self, data):
""" Check if the values to import are correct
"""Check if the values to import are correct
Pro-actively check before the ``Model.update`` if some fields
are missing or invalid
Expand Down
4 changes: 1 addition & 3 deletions connector_magento/components/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ def run(self, external_id, binding, mapper=None):
)
if not storeviews:
return
lang2storeview = {
storeview.lang_id: storeview for storeview in storeviews
}
lang2storeview = {storeview.lang_id: storeview for storeview in storeviews}

# find the translatable fields of the model
fields = self.model.fields_get()
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/doc/api/api_models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ Synchronized Models
Invoice
=======

.. automodule:: odoo.addons.connector_magento.models.account_invoice.common
.. automodule:: odoo.addons.connector_magento.models.account_move.common
:show-inheritance:
:private-members:
.. :members:
:undoc-members:
.. automodule:: odoo.addons.connector_magento.models.account_invoice.exporter
.. automodule:: odoo.addons.connector_magento.models.account_move.exporter
:members:
:undoc-members:
:show-inheritance:
Expand Down
2 changes: 1 addition & 1 deletion connector_magento/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# © 2016 Sodexis
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from openerp.addons.connector.exception import RetryableJobError
from odoo.addons.connector.exception import RetryableJobError


class OrderImportRuleRetry(RetryableJobError):
Expand Down
Loading

0 comments on commit f53584b

Please sign in to comment.