mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-21 14:19:39 +02:00
Update Plaid cash balance on each sync
This commit is contained in:
parent
46131fb496
commit
b2a56aefc1
1 changed files with 12 additions and 1 deletions
|
@ -37,7 +37,9 @@ class PlaidAccount < ApplicationRecord
|
||||||
plaid_subtype: plaid_account_data.subtype,
|
plaid_subtype: plaid_account_data.subtype,
|
||||||
account_attributes: {
|
account_attributes: {
|
||||||
id: account.id,
|
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
|
end
|
||||||
|
@ -208,4 +210,13 @@ class PlaidAccount < ApplicationRecord
|
||||||
|
|
||||||
family.merchants.find_or_create_by!(name: plaid_merchant_name)
|
family.merchants.find_or_create_by!(name: plaid_merchant_name)
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue