06/03 Optimize codes, save synced balances
This commit is contained in:
+13
-9
@@ -59,9 +59,21 @@ def index():
|
||||
if tab not in ('bank', 'credit'):
|
||||
tab = 'bank'
|
||||
|
||||
from app.models.teller_enrollment import TellerAccount
|
||||
all_accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all()
|
||||
|
||||
# Build Teller map first so we can skip calc_balance for Teller-linked accounts.
|
||||
# Their balance comes from Teller (live refresh or transaction sync) and must not
|
||||
# be overwritten by the transaction-computed sum on every page load.
|
||||
teller_accounts = TellerAccount.query.filter(
|
||||
TellerAccount.pfm_account_id.in_([a.id for a in all_accounts]),
|
||||
TellerAccount.is_active == True,
|
||||
).all()
|
||||
teller_map = {ta.pfm_account_id: ta for ta in teller_accounts}
|
||||
|
||||
for a in all_accounts:
|
||||
calc_balance(a.id)
|
||||
if a.id not in teller_map:
|
||||
calc_balance(a.id)
|
||||
all_accounts = Account.query.filter_by(is_active=True).order_by(Account.name).all()
|
||||
|
||||
bank_accounts = [a for a in all_accounts if a.account_type in BANK_TYPES]
|
||||
@@ -83,14 +95,6 @@ def index():
|
||||
).group_by(Transaction.account_id).all()
|
||||
monthly_charges = {row[0]: float(row[1]) for row in rows}
|
||||
|
||||
# Teller account mapping: pfm_account_id → TellerAccount
|
||||
from app.models.teller_enrollment import TellerAccount
|
||||
teller_accounts = TellerAccount.query.filter(
|
||||
TellerAccount.pfm_account_id.in_([a.id for a in all_accounts]),
|
||||
TellerAccount.is_active == True,
|
||||
).all()
|
||||
teller_map = {ta.pfm_account_id: ta for ta in teller_accounts}
|
||||
|
||||
return render_template('accounts/index.html',
|
||||
accounts=accounts,
|
||||
tab=tab,
|
||||
|
||||
Reference in New Issue
Block a user