Skip to content

Commit ba25795

Browse files
committed
fix: bad pagination
1 parent dab6248 commit ba25795

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/psebpconnector/connector.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ def export_orders_and_products(self):
406406
self._process_order(order)
407407
except InvalidOrder:
408408
self.logger.warning(f"Skipping order {order.id}")
409+
if order.is_refund:
410+
self.webservice.refund_error_counter += 1
411+
else:
412+
self.webservice.order_error_counter += 1
409413
finally:
410414
exported_orders_counter += 1
411415

src/psebpconnector/webservice.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ def __init__(self, url: str, apikey: str):
5151
'Io-Format': 'JSON',
5252
}
5353

54+
self.order_error_counter = 0
55+
self.refund_error_counter = 0
56+
5457
def _build_credentials(self) -> HTTPBasicAuth:
5558
return HTTPBasicAuth(self.apikey, '')
5659

@@ -134,21 +137,19 @@ def get_orders_to_export(self, valid_orders_status: List[str], refund_orders_sta
134137
exporting_regular_orders = True
135138
exporting_refunds = False
136139
for i in range(self._MAX_CALLS):
137-
offset = i * self._PAGINATION_SIZE
138-
139140
if exporting_regular_orders:
140141
result = self._do_api_call(self._build_url('orders_with_printed', {
141142
'filter[orders_printed][exported]': '0',
142143
'filter[current_state]': '[' + '|'.join(valid_orders_status) + ']',
143144
'sort': '[id_ASC]',
144-
'limit': f"{offset},{self._PAGINATION_SIZE}"
145+
'limit': f"{self.order_error_counter},{self.order_error_counter + self._PAGINATION_SIZE}"
145146
}))
146147
elif exporting_refunds:
147148
result = self._do_api_call(self._build_url('orders_with_printed', {
148149
'filter[orders_printed][exported]': '1',
149150
'filter[current_state]': '[' + '|'.join(refund_orders_status) + ']',
150151
'sort': '[id_ASC]',
151-
'limit': f"{offset},{self._PAGINATION_SIZE}"
152+
'limit': f"{self.refund_error_counter},{self.refund_error_counter + self._PAGINATION_SIZE}"
152153
}))
153154
else:
154155
break

0 commit comments

Comments
 (0)