mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
* Basic plaid data model and linking * Remove institutions, add plaid items * Improve schema and Plaid provider * Add webhook verification sketch * Webhook verification * Item accounts and balances sync setup * Provide test encryption keys * Fix test * Only provide encryption keys in prod * Try defining keys in test env * Consolidate account sync logic * Add back plaid account initialization * Plaid transaction sync * Sync UI overhaul for Plaid * Add liability and investment syncing * Handle investment webhooks and process current day holdings * Remove logs * Remove "all" period select for performance * fix amount calc * Remove todo comment * Coming soon for investment historical data * Document Plaid configuration * Listen for holding updates
53 lines
1 KiB
Ruby
53 lines
1 KiB
Ruby
class Account::Valuation < ApplicationRecord
|
|
include Account::Entryable
|
|
|
|
class << self
|
|
def search(_params)
|
|
all
|
|
end
|
|
|
|
def requires_search?(_params)
|
|
false
|
|
end
|
|
end
|
|
|
|
def name
|
|
entry.name || (oldest? ? "Initial balance" : "Balance update")
|
|
end
|
|
|
|
def trend
|
|
@trend ||= create_trend
|
|
end
|
|
|
|
def icon
|
|
oldest? ? "plus" : entry.trend.icon
|
|
end
|
|
|
|
def color
|
|
oldest? ? "#D444F1" : entry.trend.color
|
|
end
|
|
|
|
private
|
|
def oldest?
|
|
@oldest ||= account.entries.where("date < ?", entry.date).empty?
|
|
end
|
|
|
|
def account
|
|
@account ||= entry.account
|
|
end
|
|
|
|
def create_trend
|
|
TimeSeries::Trend.new(
|
|
current: entry.amount_money,
|
|
previous: prior_balance&.balance_money,
|
|
favorable_direction: account.favorable_direction
|
|
)
|
|
end
|
|
|
|
def prior_balance
|
|
@prior_balance ||= account.balances
|
|
.where("date < ?", entry.date)
|
|
.order(date: :desc)
|
|
.first
|
|
end
|
|
end
|