06/03 Optimize codes, save synced balances

This commit is contained in:
2026-06-03 10:33:04 -04:00
parent 395a2d9535
commit faacd4d91a
3 changed files with 18 additions and 14 deletions
+4 -3
View File
@@ -316,9 +316,10 @@ def refresh_balance(teller_account_id):
ledger = float(bal_data.get('ledger') or bal_data.get('available') or 0)
# Credit cards: 'available' is the remaining credit line, not what's owed.
# Use 'ledger' (amount owed, negative in Teller's convention) for credit cards.
# Use 'ledger' for credit cards and force it negative (our debt convention).
# Teller may return ledger as positive or negative depending on the bank.
is_credit = ta.pfm_account.account_type == 'credit_card'
balance_to_store = ledger if is_credit else available
balance_to_store = -abs(ledger) if is_credit else available
ta.pfm_account.balance = balance_to_store
db.session.commit()
@@ -353,7 +354,7 @@ def refresh_all_balances():
available = float(bal_data.get('available') or bal_data.get('ledger') or 0)
ledger = float(bal_data.get('ledger') or bal_data.get('available') or 0)
is_credit = ta.pfm_account.account_type == 'credit_card'
ta.pfm_account.balance = ledger if is_credit else available
ta.pfm_account.balance = -abs(ledger) if is_credit else available
refreshed.append(ta.account_name)
log.info('[teller] balance refreshed: %s = %.2f', ta.account_name, ta.pfm_account.balance)
except Exception as exc: