mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Add accounts management list (#522)
* Add accounts management * Normalize i18n file * Get turbo streams working * Ignore disabled accounts in calculations * Add empty state
This commit is contained in:
parent
0e77bab00b
commit
ad7136cb63
12 changed files with 164 additions and 25 deletions
|
@ -7,6 +7,8 @@ class Account < ApplicationRecord
|
|||
has_many :valuations
|
||||
has_many :transactions
|
||||
|
||||
scope :active, -> { where(is_active: true) }
|
||||
|
||||
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
|
||||
|
||||
before_create :check_currency
|
||||
|
@ -17,10 +19,15 @@ class Account < ApplicationRecord
|
|||
Trend.new(current: last.balance, previous: first.balance, type: classification)
|
||||
end
|
||||
|
||||
def self.by_provider
|
||||
# TODO: When 3rd party providers are supported, dynamically load all providers and their accounts
|
||||
[ { name: "Manual accounts", accounts: all.order(balance: :desc).group_by(&:accountable_type) } ]
|
||||
end
|
||||
|
||||
# TODO: We will need a better way to encapsulate large queries & transformation logic, but leaving all in one spot until
|
||||
# we have a better understanding of the requirements
|
||||
def self.by_group(period = Period.all)
|
||||
ranked_balances_cte = joins(:balances)
|
||||
ranked_balances_cte = active.joins(:balances)
|
||||
.select("
|
||||
account_balances.account_id,
|
||||
account_balances.balance,
|
||||
|
|
|
@ -4,15 +4,15 @@ class Family < ApplicationRecord
|
|||
has_many :transactions, through: :accounts
|
||||
|
||||
def net_worth
|
||||
accounts.sum("CASE WHEN classification = 'asset' THEN balance ELSE -balance END")
|
||||
accounts.active.sum("CASE WHEN classification = 'asset' THEN balance ELSE -balance END")
|
||||
end
|
||||
|
||||
def assets
|
||||
accounts.where(classification: "asset").sum(:balance)
|
||||
accounts.active.where(classification: "asset").sum(:balance)
|
||||
end
|
||||
|
||||
def liabilities
|
||||
accounts.where(classification: "liability").sum(:balance)
|
||||
accounts.active.where(classification: "liability").sum(:balance)
|
||||
end
|
||||
|
||||
def net_worth_series(period = nil)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue