feat: manual link customer to e-conomic (v1.3.58)
- Added POST /api/v1/customers/{id}/link-economic endpoint
- Allows manually setting economic_customer_number for customers without CVR
- Useful for vTiger customers that can't auto-match via CVR or name
- Updates last_synced_at timestamp when linking
This commit is contained in:
parent
c254e7cb76
commit
1b0217ef7b
@ -288,6 +288,45 @@ async def update_customer(customer_id: int, update: CustomerUpdate):
|
|||||||
raise HTTPException(status_code=500, detail=str(e))
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
|
@router.post("/customers/{customer_id}/link-economic")
|
||||||
|
async def link_economic_customer(customer_id: int, link_request: dict):
|
||||||
|
"""Manually link customer to e-conomic customer number"""
|
||||||
|
try:
|
||||||
|
economic_customer_number = link_request.get('economic_customer_number')
|
||||||
|
|
||||||
|
if not economic_customer_number:
|
||||||
|
raise HTTPException(status_code=400, detail="economic_customer_number required")
|
||||||
|
|
||||||
|
# Get customer
|
||||||
|
customer = execute_query_single(
|
||||||
|
"SELECT id, name FROM customers WHERE id = %s",
|
||||||
|
(customer_id,))
|
||||||
|
|
||||||
|
if not customer:
|
||||||
|
raise HTTPException(status_code=404, detail="Customer not found")
|
||||||
|
|
||||||
|
# Update economic customer number
|
||||||
|
execute_query(
|
||||||
|
"UPDATE customers SET economic_customer_number = %s, last_synced_at = NOW() WHERE id = %s",
|
||||||
|
(economic_customer_number, customer_id)
|
||||||
|
)
|
||||||
|
|
||||||
|
logger.info(f"✅ Linked customer {customer_id} ({customer['name']}) to e-conomic #{economic_customer_number}")
|
||||||
|
|
||||||
|
return {
|
||||||
|
"status": "success",
|
||||||
|
"message": f"Kunde linket til e-conomic kundenr. {economic_customer_number}",
|
||||||
|
"customer_id": customer_id,
|
||||||
|
"economic_customer_number": economic_customer_number
|
||||||
|
}
|
||||||
|
|
||||||
|
except HTTPException:
|
||||||
|
raise
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"❌ Failed to link customer {customer_id} to e-conomic: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail=str(e))
|
||||||
|
|
||||||
|
|
||||||
@router.post("/customers/{customer_id}/subscriptions/lock")
|
@router.post("/customers/{customer_id}/subscriptions/lock")
|
||||||
async def lock_customer_subscriptions(customer_id: int, lock_request: dict):
|
async def lock_customer_subscriptions(customer_id: int, lock_request: dict):
|
||||||
"""Lock/unlock subscriptions for customer in local DB - BMC Låst status controlled in vTiger"""
|
"""Lock/unlock subscriptions for customer in local DB - BMC Låst status controlled in vTiger"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user