mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Add Local Development Demo Data (#502)
* Clean up seeds, add development demo data * Handle liability account display and sync * Fix tests
This commit is contained in:
parent
dbf575c02a
commit
14641d16de
12 changed files with 368 additions and 62 deletions
|
@ -12,6 +12,21 @@ class Account < ApplicationRecord
|
|||
delegate :type_name, to: :accountable
|
||||
before_create :check_currency
|
||||
|
||||
def classification
|
||||
classifications = {
|
||||
"Account::Depository" => :asset,
|
||||
"Account::Investment" => :asset,
|
||||
"Account::Property" => :asset,
|
||||
"Account::Vehicle" => :asset,
|
||||
"Account::OtherAsset" => :asset,
|
||||
"Account::Loan" => :liability,
|
||||
"Account::Credit" => :liability,
|
||||
"Account::OtherLiability" => :liability
|
||||
}
|
||||
|
||||
classifications[accountable_type]
|
||||
end
|
||||
|
||||
def balance_series(period)
|
||||
filtered_balances = balances.in_period(period).order(:date)
|
||||
return nil if filtered_balances.empty?
|
||||
|
|
|
@ -11,6 +11,7 @@ class Account::BalanceCalculator
|
|||
oldest_entry = [ valuations.first, transactions.first ].compact.min_by(&:date)
|
||||
|
||||
net_transaction_flows = transactions.sum(&:amount)
|
||||
net_transaction_flows *= -1 if @account.classification == :liability
|
||||
implied_start_balance = oldest_entry.is_a?(Valuation) ? oldest_entry.value : @account.balance + net_transaction_flows
|
||||
|
||||
prior_balance = implied_start_balance
|
||||
|
@ -21,6 +22,7 @@ class Account::BalanceCalculator
|
|||
current_balance = valuation.value
|
||||
else
|
||||
current_day_net_transaction_flows = transactions.select { |t| t.date == date }.sum(&:amount)
|
||||
current_day_net_transaction_flows *= -1 if @account.classification == :liability
|
||||
current_balance = prior_balance - current_day_net_transaction_flows
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue