Fix: Check for existing customer by CVR også (undgå duplicate key error)
This commit is contained in:
parent
198c6c56f4
commit
62fc3cb4dd
@ -345,12 +345,19 @@ async def sync_from_economic() -> Dict[str, Any]:
|
||||
# Extract email domain
|
||||
email_domain = email.split('@')[-1] if '@' in email else None
|
||||
|
||||
# Check if customer exists by economic_customer_number
|
||||
# Check if customer exists by economic_customer_number OR CVR
|
||||
existing = execute_query(
|
||||
"SELECT id FROM customers WHERE economic_customer_number = %s",
|
||||
(customer_number,)
|
||||
)
|
||||
|
||||
# If not found by customer number, try CVR (to avoid duplicates)
|
||||
if not existing and cvr:
|
||||
existing = execute_query(
|
||||
"SELECT id FROM customers WHERE cvr_number = %s",
|
||||
(cvr,)
|
||||
)
|
||||
|
||||
if existing:
|
||||
# Update existing customer
|
||||
update_query = """
|
||||
|
||||
Loading…
Reference in New Issue
Block a user