1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00
Maybe/app/models/assistant/function/get_accounts.rb
Zach Gollwitzer 5da4bb6dc3
Subscription tests and domain (#2209)
* Save work

* Subscriptions and trials domain

* Store family ID on customer

* Remove indirection of stripe calls

* Test simplifications

* Update brakeman

* Fix stripe tests in CI

* Update billing page to show subscription details

* Remove legacy columns

* Complete billing settings page

* Fix hardcoded plan name

* Handle subscriptions for self hosting mode

* Lint fixes
2025-05-06 14:05:21 -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")
to_ai_time_series(balance_series)
end
end