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/balance_sheet.rb
Zach Gollwitzer 10ce2c8e23
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions
Balance sheet cache layer, non-blocking sync UI (#2356)
* Balance sheet cache layer with cache-busting

* Update family cache timestamps during Sync

* Less blocking sync loaders

* Consolidate family data caching key logic

* Fix turbo stream broadcasts

* Remove dev delay

* Add back account group sorting
2025-06-10 18:20:06 -04:00

64 lines
1.3 KiB
Ruby

class BalanceSheet
include Monetizable
monetize :net_worth
attr_reader :family
def initialize(family)
@family = family
end
def assets
@assets ||= ClassificationGroup.new(
classification: "asset",
currency: family.currency,
accounts: account_totals.asset_accounts
)
end
def liabilities
@liabilities ||= ClassificationGroup.new(
classification: "liability",
currency: family.currency,
accounts: account_totals.liability_accounts
)
end
def classification_groups
[ assets, liabilities ]
end
def account_groups
[ assets.account_groups, liabilities.account_groups ].flatten
end
def net_worth
assets.total - liabilities.total
end
def net_worth_series(period: Period.last_30_days)
net_worth_series_builder.net_worth_series(period: period)
end
def currency
family.currency
end
def syncing?
sync_status_monitor.syncing?
end
private
def sync_status_monitor
@sync_status_monitor ||= SyncStatusMonitor.new(family)
end
def account_totals
@account_totals ||= AccountTotals.new(family, sync_status_monitor: sync_status_monitor)
end
def net_worth_series_builder
@net_worth_series_builder ||= NetWorthSeriesBuilder.new(family)
end
end