Basic account onboarding (#1328)

* Basic account onboarding

* Cleanup
This commit is contained in:
Zach Gollwitzer
2024-10-18 17:18:54 -04:00
committed by GitHub
parent e8e100e1d8
commit 263d65ea7e
24 changed files with 146 additions and 73 deletions

View File

@@ -1,7 +1,10 @@
class Account < ApplicationRecord
VALUE_MODES = %w[balance transactions]
include Syncable, Monetizable, Issuable
validates :name, :balance, :currency, presence: true
validates :mode, inclusion: { in: VALUE_MODES }, allow_nil: true
belongs_to :family
belongs_to :institution, optional: true

View File

@@ -23,11 +23,11 @@ class Account::Balance::Calculator
attr_reader :account, :sync_start_date
def find_start_balance_for_partial_sync
account.balances.find_by(currency: account.currency, date: sync_start_date - 1.day).balance
account.balances.find_by(currency: account.currency, date: sync_start_date - 1.day)&.balance
end
def find_start_balance_for_full_sync(cached_entries)
account.balance + net_entry_flows(cached_entries)
account.balance + net_entry_flows(cached_entries.select { |e| e.account_transaction? })
end
def calculate_balance_for_date(date, entries:, prior_balance:)