Skip to content

Commit

Permalink
fix: bad pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Guiiix committed Jan 21, 2025
1 parent dab6248 commit ba25795
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions src/psebpconnector/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,10 @@ def export_orders_and_products(self):
self._process_order(order)
except InvalidOrder:
self.logger.warning(f"Skipping order {order.id}")
if order.is_refund:
self.webservice.refund_error_counter += 1
else:
self.webservice.order_error_counter += 1
finally:
exported_orders_counter += 1

Expand Down
9 changes: 5 additions & 4 deletions src/psebpconnector/webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ def __init__(self, url: str, apikey: str):
'Io-Format': 'JSON',
}

self.order_error_counter = 0
self.refund_error_counter = 0

def _build_credentials(self) -> HTTPBasicAuth:
return HTTPBasicAuth(self.apikey, '')

Expand Down Expand Up @@ -134,21 +137,19 @@ def get_orders_to_export(self, valid_orders_status: List[str], refund_orders_sta
exporting_regular_orders = True
exporting_refunds = False
for i in range(self._MAX_CALLS):
offset = i * self._PAGINATION_SIZE

if exporting_regular_orders:
result = self._do_api_call(self._build_url('orders_with_printed', {
'filter[orders_printed][exported]': '0',
'filter[current_state]': '[' + '|'.join(valid_orders_status) + ']',
'sort': '[id_ASC]',
'limit': f"{offset},{self._PAGINATION_SIZE}"
'limit': f"{self.order_error_counter},{self.order_error_counter + self._PAGINATION_SIZE}"
}))
elif exporting_refunds:
result = self._do_api_call(self._build_url('orders_with_printed', {
'filter[orders_printed][exported]': '1',
'filter[current_state]': '[' + '|'.join(refund_orders_status) + ']',
'sort': '[id_ASC]',
'limit': f"{offset},{self._PAGINATION_SIZE}"
'limit': f"{self.refund_error_counter},{self.refund_error_counter + self._PAGINATION_SIZE}"
}))
else:
break
Expand Down

0 comments on commit ba25795

Please sign in to comment.