Fix: Implementeret pagination i vTiger sync for at hente ALLE kunder (batch size 200)

This commit is contained in:
Christian 2025-12-22 12:53:11 +01:00
parent af6e868828
commit 94781227b2

View File

@ -36,11 +36,29 @@ async def sync_from_vtiger() -> Dict[str, Any]:
vtiger = get_vtiger_service() vtiger = get_vtiger_service()
# Query vTiger for all accounts with CVR or name (no limit to get all) # Fetch ALL accounts using pagination (vTiger limits to ~200 per request)
query = "SELECT id, accountname, email1, siccode, cf_accounts_cvr, website, bill_city, bill_code, bill_country FROM Accounts;" all_accounts = []
offset = 0
batch_size = 200
accounts = await vtiger.query(query) while True:
logger.info(f"📥 Fetched {len(accounts)} accounts from vTiger") query = f"SELECT id, accountname, email1, siccode, cf_accounts_cvr, website, bill_city, bill_code, bill_country FROM Accounts LIMIT {batch_size} OFFSET {offset};"
batch = await vtiger.query(query)
if not batch or len(batch) == 0:
break
all_accounts.extend(batch)
logger.info(f"📥 Fetched batch: {len(batch)} accounts (total so far: {len(all_accounts)})")
# If we got less than batch_size, we've reached the end
if len(batch) < batch_size:
break
offset += batch_size
logger.info(f"📥 Fetched total of {len(all_accounts)} accounts from vTiger")
accounts = all_accounts
created_count = 0 created_count = 0
updated_count = 0 updated_count = 0