[IMP] connector_opencart: avoid making a queue.job for an already imported order

This commit is contained in:
Jared Kipe
2021-08-24 10:20:29 -07:00
parent 6c45c0380c
commit af42f105d3
2 changed files with 9 additions and 2 deletions

View File

@@ -84,8 +84,7 @@ class Orders(Resource):
if id_larger_than: if id_larger_than:
url += '/id_larger_than/%s' % id_larger_than url += '/id_larger_than/%s' % id_larger_than
if modified_from: if modified_from:
# TODO remove details if it gets into main route url += '/modified_from/%s' % modified_from
url += 'details/modified_from/%s' % modified_from
return self.connection.send_request(method='GET', url=url) return self.connection.send_request(method='GET', url=url)
def get(self, id): def get(self, id):

View File

@@ -26,6 +26,13 @@ class SaleOrderBatchImporter(Component):
'max_retries': 0, 'max_retries': 0,
'priority': 5, 'priority': 5,
} }
# It is very likely that we already have this order because we may have just uploaded a tracking number
# We want to avoid creating queue jobs for orders already imported.
order_binder = self.binder_for('opencart.sale.order')
order = order_binder.to_internal(external_id)
if order:
_logger.warning('Order (%s) already imported.' % (order.name, ))
return
if store_id is not None: if store_id is not None:
store_binder = self.binder_for('opencart.store') store_binder = self.binder_for('opencart.store')
store = store_binder.to_internal(store_id).sudo() store = store_binder.to_internal(store_id).sudo()
@@ -48,6 +55,7 @@ class SaleOrderBatchImporter(Component):
filters = {} filters = {}
external_ids = list(self.backend_adapter.search(filters)) external_ids = list(self.backend_adapter.search(filters))
for ids in external_ids: for ids in external_ids:
_logger.debug('run._import_record for %s' % (ids, ))
self._import_record(ids[0], ids[1]) self._import_record(ids[0], ids[1])
if external_ids: if external_ids:
last_id = list(sorted(external_ids, key=lambda i: i[0]))[-1][0] last_id = list(sorted(external_ids, key=lambda i: i[0]))[-1][0]