Add detailed sync logging with precise changes (oprettet/opdateret/linket med firma/CVR info)
This commit is contained in:
parent
c8e005dd07
commit
55478c20d3
@ -54,6 +54,7 @@ async def sync_from_vtiger() -> Dict[str, Any]:
|
||||
|
||||
if not name:
|
||||
skipped_count += 1
|
||||
logger.debug(f"⏭️ Sprunget over: Tomt firmanavn (ID: {vtiger_id})")
|
||||
continue
|
||||
|
||||
# Clean CVR number
|
||||
@ -109,7 +110,7 @@ async def sync_from_vtiger() -> Dict[str, Any]:
|
||||
query = f"UPDATE customers SET {', '.join(update_fields)} WHERE id = %s"
|
||||
execute_query(query, tuple(params))
|
||||
updated_count += 1
|
||||
logger.debug(f"✅ Updated: {name}")
|
||||
logger.info(f"✏️ Opdateret: {name} (CVR: {cvr or 'ingen'}) - Felter: {', '.join([f.split(' = ')[0] for f in update_fields if 'last_synced' not in f])}")
|
||||
else:
|
||||
# Create new customer
|
||||
insert_query = """
|
||||
@ -140,9 +141,9 @@ async def sync_from_vtiger() -> Dict[str, Any]:
|
||||
|
||||
if result:
|
||||
created_count += 1
|
||||
logger.debug(f"✨ Created: {name}")
|
||||
logger.info(f"✨ Oprettet: {name} (CVR: {cvr or 'ingen'}, By: {city or 'ukendt'})")
|
||||
|
||||
logger.info(f"✅ vTiger sync complete: {created_count} created, {updated_count} updated, {skipped_count} skipped")
|
||||
logger.info(f"✅ vTiger sync fuldført: {created_count} oprettet, {updated_count} opdateret, {skipped_count} sprunget over af {len(accounts)} totalt")
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
@ -185,6 +186,7 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
|
||||
|
||||
if not (first_name or last_name):
|
||||
skipped_count += 1
|
||||
logger.debug(f"⏭️ Sprunget over: Intet navn (ID: {vtiger_contact_id})")
|
||||
continue
|
||||
|
||||
# Find existing contact by vTiger ID
|
||||
@ -226,6 +228,7 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
|
||||
))
|
||||
updated_count += 1
|
||||
contact_id = existing[0]['id']
|
||||
logger.info(f"✏️ Opdateret kontakt: {first_name} {last_name} (Email: {contact_data['email'] or 'ingen'})")
|
||||
else:
|
||||
# Create new contact
|
||||
insert_query = """
|
||||
@ -248,8 +251,10 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
|
||||
if result:
|
||||
created_count += 1
|
||||
contact_id = result[0]['id']
|
||||
logger.info(f"✨ Oprettet kontakt: {first_name} {last_name} (Email: {contact_data['email'] or 'ingen'})")
|
||||
else:
|
||||
skipped_count += 1
|
||||
logger.warning(f"⚠️ Kunne ikke oprette kontakt: {first_name} {last_name}")
|
||||
continue
|
||||
|
||||
# Link contact to customer if account_id exists
|
||||
@ -262,6 +267,8 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
|
||||
)
|
||||
|
||||
if customer:
|
||||
customer_name_result = execute_query("SELECT name FROM customers WHERE id = %s", (customer[0]['id'],))
|
||||
customer_name = customer_name_result[0]['name'] if customer_name_result else 'ukendt'
|
||||
# Check if relationship exists
|
||||
existing_rel = execute_query(
|
||||
"SELECT id FROM contact_companies WHERE contact_id = %s AND customer_id = %s",
|
||||
@ -274,8 +281,9 @@ async def sync_vtiger_contacts() -> Dict[str, Any]:
|
||||
"INSERT INTO contact_companies (contact_id, customer_id, is_primary) VALUES (%s, %s, false)",
|
||||
(contact_id, customer[0]['id'])
|
||||
)
|
||||
logger.info(f"🔗 Linket kontakt {first_name} {last_name} til firma: {customer_name}")
|
||||
|
||||
logger.info(f"✅ vTiger contacts sync complete: {created_count} created, {updated_count} updated, {skipped_count} skipped")
|
||||
logger.info(f"✅ vTiger kontakt sync fuldført: {created_count} oprettet, {updated_count} opdateret, {skipped_count} sprunget over af {len(contacts)} totalt")
|
||||
|
||||
return {
|
||||
"status": "success",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user