Fix: Rettet indentation fejl i kontakt linking kode
This commit is contained in:
parent
0b8a4ff5d0
commit
0fb404dff5
@ -285,40 +285,42 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
|
||||
# Link contact to customer if account_id exists
|
||||
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:
|
||||
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
|
||||
|
||||
if account_id and contact_id:
|
||||
# Find customer by vTiger account ID
|
||||
customer = execute_query(
|
||||
"SELECT id, name FROM customers WHERE vtiger_id = %s",
|
||||
(account_id,)
|
||||
if not account_id:
|
||||
continue # Skip if no account_id
|
||||
|
||||
if not contact_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:
|
||||
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",
|
||||
if not existing_rel:
|
||||
# Create relationship
|
||||
execute_query(
|
||||
"INSERT INTO contact_companies (contact_id, customer_id, is_primary) VALUES (%s, %s, false)",
|
||||
(contact_id, customer[0]['id'])
|
||||
)
|
||||
|
||||
if not existing_rel:
|
||||
# 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})")
|
||||
linked_count += 1
|
||||
logger.info(f"🔗 Linket kontakt {first_name} {last_name} til firma: {customer_name}")
|
||||
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")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user