1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-02 20:15:22 +02:00

Show cash + holdings value for investment account view (#1046)

* Handle missing tickers in security price syncs

* Show combined cash and holdings value on account page

* Improve partial locals
This commit is contained in:
Zach Gollwitzer 2024-08-02 17:09:25 -04:00 committed by GitHub
parent 453a54e5e6
commit ea8309eedd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
20 changed files with 168 additions and 33 deletions

View file

@ -28,8 +28,10 @@ class Account < ApplicationRecord
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
delegate :value, :series, to: :accountable
class << self
def by_group(period: Period.all, currency: Money.default_currency)
def by_group(period: Period.all, currency: Money.default_currency.iso_code)
grouped_accounts = { assets: ValueGroup.new("Assets", currency), liabilities: ValueGroup.new("Liabilities", currency) }
Accountable.by_classification.each do |classification, types|
@ -82,18 +84,6 @@ class Account < ApplicationRecord
classification == "asset" ? "up" : "down"
end
def series(period: Period.all, currency: self.currency)
balance_series = balances.in_period(period).where(currency: Money::Currency.new(currency).iso_code)
if balance_series.empty? && period.date_range.end == Date.current
TimeSeries.new([ { date: Date.current, value: balance_money.exchange_to(currency) } ])
else
TimeSeries.from_collection(balance_series, :balance_money)
end
rescue Money::ConversionError
TimeSeries.new([])
end
def update_balance!(balance)
valuation = entries.account_valuations.find_by(date: Date.current)