fix: merge account details into balance data to prevent unknown/N/A values

- Modified sync service to include institution_id and iban in balance persistence
- Fixed data flow issue where balance records were missing account metadata
- Prevents future balance records from having 'unknown' bank or 'N/A' IBAN
- Successfully fixed 8 existing records with one-off script
This commit is contained in:
Elisiário Couto
2025-09-09 15:32:32 +01:00
committed by Elisiário Couto
parent 34501f5f0d
commit eaaea6e459

View File

@@ -61,8 +61,16 @@ class SyncService:
# Get and save balances
balances = await self.gocardless.get_account_balances(account_id)
if balances:
await self.database.persist_balance(account_id, balances)
if balances and account_details:
# Merge account details into balances data for proper persistence
balances_with_account_info = balances.copy()
balances_with_account_info["institution_id"] = (
account_details.get("institution_id")
)
balances_with_account_info["iban"] = account_details.get("iban")
await self.database.persist_balance(
account_id, balances_with_account_info
)
balances_updated += len(balances.get("balances", []))
# Get and save transactions