Compare commits

..

2 Commits

Author SHA1 Message Date
Christian
ea062e10ae chore: Bump version to 1.3.133 2026-01-27 01:53:42 +01:00
Christian
cb7e209769 fix: Add pagination to e-conomic API to fetch ALL invoices (not just first 1000) 2026-01-27 01:53:34 +01:00
2 changed files with 45 additions and 27 deletions

View File

@ -1 +1 @@
1.3.132
1.3.133

View File

@ -470,17 +470,24 @@ class EconomicService:
logger.info(f"📋 Trying invoice endpoint: {endpoint}")
try:
# Pagination: Keep fetching until no more pages
page = 0
while True:
async with session.get(
endpoint,
params={"pagesize": 1000},
params={"pagesize": 1000, "skippages": page},
headers=self._get_headers()
) as response:
logger.info(f"🔍 [API] Response status from {endpoint}: {response.status}")
logger.info(f"🔍 [API] Response status from {endpoint} (page {page}): {response.status}")
if response.status == 200:
data = await response.json()
invoices_from_endpoint = data.get('collection', [])
logger.info(f"✅ Successfully fetched {len(invoices_from_endpoint)} invoices from {endpoint}")
logger.info(f"✅ Fetched {len(invoices_from_endpoint)} invoices from {endpoint} page {page}")
if not invoices_from_endpoint:
# No more invoices on this page
break
# Add new invoices (avoid duplicates by tracking invoice numbers)
existing_invoice_numbers = set()
@ -489,14 +496,25 @@ class EconomicService:
if inv_num:
existing_invoice_numbers.add(inv_num)
new_invoices_count = 0
for inv in invoices_from_endpoint:
inv_num = inv.get('draftInvoiceNumber') or inv.get('bookedInvoiceNumber')
if inv_num and inv_num not in existing_invoice_numbers:
all_invoices.append(inv)
existing_invoice_numbers.add(inv_num)
new_invoices_count += 1
logger.info(f" Added {new_invoices_count} new unique invoices")
# Check if we got full page (1000) - if so, there might be more pages
if len(invoices_from_endpoint) < 1000:
break # Last page
page += 1
else:
error_text = await response.text()
logger.warning(f"⚠️ Endpoint {endpoint} returned {response.status}: {error_text[:200]}")
break
except Exception as e:
logger.warning(f"⚠️ Error trying endpoint {endpoint}: {e}")