Fix: Rettet indentation fejl i kontakt linking kode

This commit is contained in:
Christian 2025-12-22 14:41:44 +01:00
parent 0b8a4ff5d0
commit 0fb404dff5

View File

@ -285,40 +285,42 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
# Link contact to customer if account_id exists # Link contact to customer if account_id exists
account_id = contact.get('account_id') account_id = contact.get('account_id')
# Debug: Log first 20 contacts with account_id info # ALWAYS log first 20 for debugging
if debug_counter < 20: if debug_counter < 20:
logger.info(f"🔍 Debug kontakt #{debug_counter+1}: {first_name} {last_name}, account_id='{account_id}', contact_id={contact_id if 'contact_id' in locals() else 'N/A'}") logger.warning(f"🔍 DEBUG #{debug_counter+1}: name={first_name} {last_name}, account_id='{account_id}', has_contact_id={contact_id is not None if 'contact_id' in locals() else False}")
debug_counter += 1 debug_counter += 1
if account_id and contact_id: if not account_id:
# Find customer by vTiger account ID continue # Skip if no account_id
customer = execute_query(
"SELECT id, name FROM customers WHERE vtiger_id = %s", if not contact_id:
(account_id,) logger.warning(f"⚠️ Mangler contact_id for {first_name} {last_name}")
continue
# Find customer by vTiger account ID
customer = execute_query(
"SELECT id, name FROM customers WHERE vtiger_id = %s",
(account_id,)
)
if customer:
customer_name = customer[0]['name']
# Check if relationship exists
existing_rel = execute_query(
"SELECT id FROM contact_companies WHERE contact_id = %s AND customer_id = %s",
(contact_id, customer[0]['id'])
) )
if customer: if not existing_rel:
customer_name = customer[0]['name'] # Create relationship
# Check if relationship exists execute_query(
existing_rel = execute_query( "INSERT INTO contact_companies (contact_id, customer_id, is_primary) VALUES (%s, %s, false)",
"SELECT id FROM contact_companies WHERE contact_id = %s AND customer_id = %s",
(contact_id, customer[0]['id']) (contact_id, customer[0]['id'])
) )
linked_count += 1
if not existing_rel: logger.info(f"🔗 Linket kontakt {first_name} {last_name} til firma: {customer_name}")
# Create relationship
execute_query(
"INSERT INTO contact_companies (contact_id, customer_id, is_primary) VALUES (%s, %s, false)",
(contact_id, customer[0]['id'])
)
linked_count += 1
logger.info(f"🔗 Linket kontakt {first_name} {last_name} til firma: {customer_name}")
else:
logger.info(f"⚠️ Kunde ikke fundet for account_id={account_id} (kontakt: {first_name} {last_name})")
elif account_id:
logger.info(f"⚠️ Ingen contact_id for {first_name} {last_name} (account_id={account_id})")
else: else:
logger.debug(f"⏭️ Ingen account_id for kontakt {first_name} {last_name}") logger.info(f"⚠️ Kunde ikke fundet for account_id={account_id} (kontakt: {first_name} {last_name})")
logger.info(f"✅ vTiger kontakt sync fuldført: {created_count} oprettet, {updated_count} opdateret, {linked_count} linket, {skipped_count} sprunget over af {len(contacts)} totalt") logger.info(f"✅ vTiger kontakt sync fuldført: {created_count} oprettet, {updated_count} opdateret, {linked_count} linket, {skipped_count} sprunget over af {len(contacts)} totalt")