Skip to content

Commit

Permalink
[FIX]CLI fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
bizzappdev committed Mar 8, 2021
1 parent 8e957e8 commit f65b4c7
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 135 deletions.
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: E231
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_path = getattr(self.model, "_get_admin_path") # noqa: B009
admin_path(backend, external_id)
else:
key = "_admin2_path" if backend.version == "2.0" else "_admin_path"
admin_path = getattr(self, key)
Expand Down
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
42 changes: 0 additions & 42 deletions connector_magento/migrations/7.0.2.5.0/post-migration.py

This file was deleted.

48 changes: 0 additions & 48 deletions connector_magento/migrations/8.0.3.0.0/pre-migration.py

This file was deleted.

8 changes: 4 additions & 4 deletions connector_magento/models/product_category/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _call(self, method, arguments, http_method=None, storeview=None):
raise

def search(self, filters=None, from_date=None, to_date=None):
""" Search records according to some criteria and return a
"""Search records according to some criteria and return a
list of ids
:rtype: list
Expand All @@ -99,7 +99,7 @@ def search(self, filters=None, from_date=None, to_date=None):
return super(ProductCategoryAdapter, self).search(filters=filters)

def read(self, external_id, storeview_id=None, attributes=None):
""" Returns the information of a record
"""Returns the information of a record
:rtype: dict
"""
Expand All @@ -114,7 +114,7 @@ def read(self, external_id, storeview_id=None, attributes=None):
)

def tree(self, parent_id=None, storeview_id=None):
""" Returns a tree of product categories
"""Returns a tree of product categories
:rtype: dict
"""
Expand Down Expand Up @@ -143,7 +143,7 @@ def move(self, categ_id, parent_id, after_categ_id=None):
)
return self._call(
"{}/{}/move".format(self._magento2_model, categ_id),
{"parent_id": parent_id, "after_id": after_categ_id,},
{"parent_id": parent_id, "after_id": after_categ_id},
)

def get_assigned_product(self, categ_id):
Expand Down
12 changes: 7 additions & 5 deletions connector_magento/models/sale_order/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _rule_global(self, record, method):
)

def check(self, record):
""" Check whether the current sale order should be imported
"""Check whether the current sale order should be imported
or not. It will actually use the payment method configuration
and see if the choosed rule is fullfilled.
Expand Down Expand Up @@ -372,7 +372,7 @@ def backend_id(self, record):

@mapping
def user_id(self, record):
""" Do not assign to a Salesperson otherwise sales orders are hidden
"""Do not assign to a Salesperson otherwise sales orders are hidden
for the salespersons (access rules)"""
return {"user_id": False}

Expand All @@ -383,7 +383,7 @@ class SaleOrderImporter(Component):
_apply_on = "magento.sale.order"

def _must_skip(self):
""" Hook called right after we read the data from the backend.
"""Hook called right after we read the data from the backend.
If the method returns a message giving a reason for the
skipping, the import will be interrupted and the message
Expand Down Expand Up @@ -470,7 +470,7 @@ def _before_import(self):
rules.check(self.magento_record)

def _link_parent_orders(self, binding):
""" Link the magento.sale.order to its parent orders.
"""Link the magento.sale.order to its parent orders.
When a Magento sales order is modified, it:
- cancel the sales order
Expand Down Expand Up @@ -815,7 +815,9 @@ def product_options(self, record):
if each.startswith('"label"'):
split_info = each.split(";")
options_label.append(
"{}: {} [{}]".format(split_info[1], split_info[3], record["sku"])
"{}: {} [{}]".format(
split_info[1], split_info[3], record["sku"]
)
)
notes = "".join(options_label).replace('""', "\n").replace('"', "")
result = {"notes": notes}
Expand Down
4 changes: 2 additions & 2 deletions connector_magento/models/stock_picking/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def _get_lines_info(self, binding):
return item_qty

def _get_picking_mail_option(self, binding):
""" Indicates if Magento has to send an email
"""Indicates if Magento has to send an email
:param binding: magento.stock.picking record
:returns: value of send_picking_done_mail chosen on magento shop
Expand Down Expand Up @@ -117,7 +117,7 @@ def get_lines_info():
else: # Magento 2.x
arguments = {
"items": [
{"order_item_id": key, "qty": val,}
{"order_item_id": key, "qty": val}
for key, val in get_lines_info().items()
]
}
Expand Down
2 changes: 1 addition & 1 deletion connector_magento/tests/magento2/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def setUp(self):
super(Magento2TestCase, self).setUp()
self.recorder = recorder
self.backend.write(
{"version": "2.0", "token": "m59qseoztake3xm1zcvkiv8qnuj09da0",}
{"version": "2.0", "token": "m59qseoztake3xm1zcvkiv8qnuj09da0"}
)


Expand Down
Loading

0 comments on commit f65b4c7

Please sign in to comment.