Debug: Tilføjet bedre logging til vTiger matching for at identificere problem

This commit is contained in:
Christian 2025-12-22 14:13:44 +01:00
parent 64935b5808
commit 0b6d286332

View File

@ -87,11 +87,15 @@ async def sync_from_vtiger() -> Dict[str, Any]:
# Find existing Hub customer by CVR or normalized name # Find existing Hub customer by CVR or normalized name
existing = None existing = None
match_method = None
if cvr: if cvr:
existing = execute_query( existing = execute_query(
"SELECT id, name, vtiger_id FROM customers WHERE cvr_number = %s", "SELECT id, name, vtiger_id FROM customers WHERE cvr_number = %s",
(cvr,) (cvr,)
) )
if existing:
match_method = "CVR"
if not existing: if not existing:
# Match by normalized name # Match by normalized name
@ -100,6 +104,7 @@ async def sync_from_vtiger() -> Dict[str, Any]:
for customer in all_customers: for customer in all_customers:
if normalize_name(customer['name']) == normalized: if normalize_name(customer['name']) == normalized:
existing = [customer] existing = [customer]
match_method = "navn"
break break
if existing: if existing:
@ -111,7 +116,7 @@ async def sync_from_vtiger() -> Dict[str, Any]:
(vtiger_id, existing[0]['id']) (vtiger_id, existing[0]['id'])
) )
linked_count += 1 linked_count += 1
logger.info(f"🔗 Linket: {existing[0]['name']} → vTiger #{vtiger_id} (CVR: {cvr or 'navn-match'})") logger.info(f"🔗 Linket: {existing[0]['name']} → vTiger #{vtiger_id} (match: {match_method}, CVR: {cvr or 'ingen'})")
elif current_vtiger_id != vtiger_id: elif current_vtiger_id != vtiger_id:
# Update if different vTiger ID # Update if different vTiger ID
execute_query( execute_query(
@ -125,7 +130,7 @@ async def sync_from_vtiger() -> Dict[str, Any]:
execute_query("UPDATE customers SET last_synced_at = NOW() WHERE id = %s", (existing[0]['id'],)) execute_query("UPDATE customers SET last_synced_at = NOW() WHERE id = %s", (existing[0]['id'],))
else: else:
not_found_count += 1 not_found_count += 1
logger.debug(f"⏭️ Ikke fundet i Hub: {name} (CVR: {cvr or 'ingen'})") logger.debug(f"⏭️ Ikke fundet i Hub: '{name}' (CVR: {cvr or 'ingen'}, normalized: '{normalize_name(name)}')")
logger.info(f"✅ vTiger link sync fuldført: {linked_count} nye linket, {updated_count} opdateret, {not_found_count} ikke fundet af {len(accounts)} totalt") logger.info(f"✅ vTiger link sync fuldført: {linked_count} nye linket, {updated_count} opdateret, {not_found_count} ikke fundet af {len(accounts)} totalt")