1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/app/models/assistant/function/get_accounts.rb
Zach Gollwitzer 2000f05453
Match Plaid holding values on current day (#2212)
* Match Plaid holding values on current day

* Fix chart timezone issue

* Add timezone tests for syncs

* Hide sidebars on trades test
2025-05-06 09:25:49 -04:00

40 lines
1.2 KiB
Ruby

class Assistant::Function::GetAccounts < Assistant::Function
class << self
def name
"get_accounts"
end
def description
"Use this to see what accounts the user has along with their current and historical balances"
end
end
def call(params = {})
{
as_of_date: Date.current,
accounts: family.accounts.includes(:balances).map do |account|
{
name: account.name,
balance: account.balance,
currency: account.currency,
balance_formatted: account.balance_money.format,
classification: account.classification,
type: account.accountable_type,
start_date: account.start_date,
is_plaid_linked: account.plaid_account_id.present?,
is_active: account.is_active,
historical_balances: historical_balances(account)
}
end
}
end
private
def historical_balances(account)
start_date = [ account.start_date, 5.years.ago.to_date ].max
period = Period.custom(start_date: start_date, end_date: Date.current)
balance_series = account.balance_series(period: period, interval: "1 month", timezone: family.timezone)
to_ai_time_series(balance_series)
end
end