Fix: Brug economic_acc_number field fra Simply-CRM (ikke account_no)
This commit is contained in:
parent
1380369dff
commit
05ec5b5903
@ -312,7 +312,18 @@ async def sync_economic_numbers_from_simplycrm():
|
|||||||
async with SimplyCRMService() as simplycrm:
|
async with SimplyCRMService() as simplycrm:
|
||||||
# Hent alle accounts fra Simply-CRM
|
# Hent alle accounts fra Simply-CRM
|
||||||
logger.info("📥 Fetching accounts from Simply-CRM...")
|
logger.info("📥 Fetching accounts from Simply-CRM...")
|
||||||
query = "SELECT accountname, cf_854 FROM Accounts LIMIT 5000;"
|
|
||||||
|
# Først: Tjek hvilke felter der er tilgængelige
|
||||||
|
try:
|
||||||
|
test_query = "SELECT * FROM Accounts LIMIT 1;"
|
||||||
|
test_result = await simplycrm.query(test_query)
|
||||||
|
if test_result:
|
||||||
|
logger.info(f"📋 Available fields: {list(test_result[0].keys())}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"⚠️ Could not fetch sample fields: {e}")
|
||||||
|
|
||||||
|
# Query med standard felter + economic_acc_number
|
||||||
|
query = "SELECT id, accountname, economic_acc_number FROM Accounts LIMIT 5000;"
|
||||||
accounts = await simplycrm.query(query)
|
accounts = await simplycrm.query(query)
|
||||||
|
|
||||||
stats["simplycrm_accounts"] = len(accounts)
|
stats["simplycrm_accounts"] = len(accounts)
|
||||||
@ -326,19 +337,24 @@ async def sync_economic_numbers_from_simplycrm():
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Filter accounts med economic customer number
|
# Filter accounts med economic customer number
|
||||||
accounts_with_economic = [
|
accounts_with_economic = []
|
||||||
acc for acc in accounts
|
for acc in accounts:
|
||||||
if acc.get('cf_854') and str(acc.get('cf_854')).strip() not in ['', '0', 'null', 'NULL']
|
economic_number = acc.get('economic_acc_number')
|
||||||
]
|
|
||||||
|
if economic_number and str(economic_number).strip() not in ['', '0', 'null', 'NULL']:
|
||||||
|
accounts_with_economic.append({
|
||||||
|
'accountname': acc.get('accountname'),
|
||||||
|
'economic_number': str(economic_number).strip()
|
||||||
|
})
|
||||||
|
|
||||||
stats["accounts_with_economic_number"] = len(accounts_with_economic)
|
stats["accounts_with_economic_number"] = len(accounts_with_economic)
|
||||||
logger.info(f"✅ {len(accounts_with_economic)} accounts have e-conomic customer numbers")
|
logger.info(f"✅ {len(accounts_with_economic)} accounts have e-conomic customer numbers")
|
||||||
|
|
||||||
# Map company name → economic_customer_number
|
# Map company name → economic_customer_number
|
||||||
name_to_economic = {}
|
name_to_economic = {}
|
||||||
for acc in accounts_with_economic:
|
for acc_data in accounts_with_economic:
|
||||||
company_name = acc.get('accountname', '').strip()
|
company_name = acc_data['accountname'].strip()
|
||||||
economic_number = str(acc.get('cf_854', '')).strip()
|
economic_number = acc_data['economic_number']
|
||||||
|
|
||||||
if company_name and economic_number:
|
if company_name and economic_number:
|
||||||
# Normalize navn til lowercase for matching
|
# Normalize navn til lowercase for matching
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user