feat: Add manual customer linking endpoint (v1.3.106)
This commit is contained in:
parent
fa55e6b98e
commit
9336edd5cc
@ -128,6 +128,54 @@ async def test_vtiger_connection():
|
|||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/sync/manual-link-customer", tags=["Sync"])
|
||||||
|
async def manual_link_customer(tmodule_customer_id: int, hub_customer_id: int):
|
||||||
|
"""
|
||||||
|
🔗 Manually link en tmodule_customer til en Hub customer.
|
||||||
|
|
||||||
|
Brug dette når auto-linking fejler pga. navn-forskelle eller andre edge cases.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
logger.info(f"🔗 Manual linking tmodule {tmodule_customer_id} → Hub {hub_customer_id}")
|
||||||
|
|
||||||
|
# Get Hub customer's economic number
|
||||||
|
hub_query = "SELECT economic_customer_number FROM customers WHERE id = %s"
|
||||||
|
hub_result = execute_query(hub_query, (hub_customer_id,))
|
||||||
|
|
||||||
|
if not hub_result:
|
||||||
|
raise HTTPException(status_code=404, detail=f"Hub customer {hub_customer_id} not found")
|
||||||
|
|
||||||
|
economic_number = hub_result[0]['economic_customer_number']
|
||||||
|
|
||||||
|
# Update tmodule_customer
|
||||||
|
update_query = """
|
||||||
|
UPDATE tmodule_customers
|
||||||
|
SET hub_customer_id = %s,
|
||||||
|
economic_customer_number = %s,
|
||||||
|
updated_at = NOW()
|
||||||
|
WHERE id = %s
|
||||||
|
RETURNING id, name, hub_customer_id, economic_customer_number
|
||||||
|
"""
|
||||||
|
|
||||||
|
result = execute_query(update_query, (hub_customer_id, economic_number, tmodule_customer_id))
|
||||||
|
|
||||||
|
if not result:
|
||||||
|
raise HTTPException(status_code=404, detail=f"tmodule_customer {tmodule_customer_id} not found")
|
||||||
|
|
||||||
|
logger.info(f"✅ Manual link complete: {result[0]}")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"success": True,
|
||||||
|
"linked_customer": result[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"❌ Manual linking failed: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.post("/sync/relink-customers", tags=["Sync"])
|
@router.post("/sync/relink-customers", tags=["Sync"])
|
||||||
async def relink_customers():
|
async def relink_customers():
|
||||||
"""
|
"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user