Skip to content

Commit

Permalink
Update Plaid cash balance on each sync
Browse files Browse the repository at this point in the history
  • Loading branch information
zachgoll committed Dec 10, 2024
1 parent 46131fb commit b2a56ae
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion app/models/plaid_account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ def sync_account_data!(plaid_account_data)
plaid_subtype: plaid_account_data.subtype,
account_attributes: {
id: account.id,
balance: plaid_account_data.balances.current
# Plaid guarantees at least 1 of these
balance: plaid_account_data.balances.current || plaid_account_data.balances.available,
cash_balance: derive_plaid_cash_balance(plaid_account_data.balances)
}
)
end
Expand Down Expand Up @@ -208,4 +210,13 @@ def get_merchant(plaid_merchant_name)

family.merchants.find_or_create_by!(name: plaid_merchant_name)
end

def derive_plaid_cash_balance(plaid_balances)
if account.investment?
plaid_balances.available || 0
else
# For now, we will not distinguish between "cash" and "overall" balance for non-investment accounts
plaid_balances.current || plaid_balances.available
end
end
end

0 comments on commit b2a56ae

Please sign in to comment.