mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Add Live Data to Account Page (#464)
* Add trends, time series, seed data * Remove test data * Replace old view values with helpers * Fix tooltip bugs in D3 chart * Fix tests * Fix smoke test * Add CRUD actions for valuations * Scaffold out inline editing with Turbo
This commit is contained in:
parent
298b50a909
commit
b5b2d335fd
28 changed files with 512 additions and 167 deletions
74
db/seeds.rb
74
db/seeds.rb
|
@ -8,6 +8,9 @@
|
|||
# MovieGenre.find_or_create_by!(name: genre_name)
|
||||
# end
|
||||
|
||||
# https://github.com/rails/rails/issues/29112#issuecomment-320653056
|
||||
ApplicationRecord.reset_column_information
|
||||
|
||||
# Create the default user
|
||||
family = Family.create_or_find_by(name: "The Maybe Family")
|
||||
puts "Family created: #{family.name}"
|
||||
|
@ -22,3 +25,74 @@ puts "User created: #{user.email} for family: #{family.name}"
|
|||
|
||||
# Create default currency
|
||||
Currency.find_or_create_by(iso_code: "USD", name: "United States Dollar")
|
||||
|
||||
current_balance = 350000
|
||||
|
||||
account = Account.create_or_find_by(name: "Seed Property Account", accountable: Account::Property.new, family: family, original_balance: current_balance, original_currency: "USD")
|
||||
puts "Account created: #{account.name}"
|
||||
|
||||
# Represent user-defined "Valuations" at various dates
|
||||
appraisals = [
|
||||
{ date: Date.today - 30, balance: 300000 },
|
||||
{ date: Date.today - 22, balance: 300700 },
|
||||
{ date: Date.today - 17, balance: 301400 },
|
||||
{ date: Date.today - 10, balance: 300000 },
|
||||
{ date: Date.today - 3, balance: 301900 }
|
||||
]
|
||||
|
||||
# In prod, this would be calculated from the current balance and the appraisals with a background job
|
||||
# Hardcoded for readability
|
||||
balances = [
|
||||
{ date: Date.today - 30, balance: 300000 },
|
||||
{ date: Date.today - 29, balance: 300000 },
|
||||
{ date: Date.today - 28, balance: 300000 },
|
||||
{ date: Date.today - 27, balance: 300000 },
|
||||
{ date: Date.today - 26, balance: 300000 },
|
||||
{ date: Date.today - 25, balance: 300000 },
|
||||
{ date: Date.today - 24, balance: 300000 },
|
||||
{ date: Date.today - 23, balance: 300000 },
|
||||
{ date: Date.today - 22, balance: 300700 },
|
||||
{ date: Date.today - 21, balance: 300700 },
|
||||
{ date: Date.today - 20, balance: 300700 },
|
||||
{ date: Date.today - 19, balance: 300700 },
|
||||
{ date: Date.today - 18, balance: 300700 },
|
||||
{ date: Date.today - 17, balance: 301400 },
|
||||
{ date: Date.today - 16, balance: 301400 },
|
||||
{ date: Date.today - 15, balance: 301400 },
|
||||
{ date: Date.today - 14, balance: 301400 },
|
||||
{ date: Date.today - 13, balance: 301400 },
|
||||
{ date: Date.today - 12, balance: 301400 },
|
||||
{ date: Date.today - 11, balance: 301400 },
|
||||
{ date: Date.today - 10, balance: 300000 },
|
||||
{ date: Date.today - 9, balance: 300000 },
|
||||
{ date: Date.today - 8, balance: 300000 },
|
||||
{ date: Date.today - 7, balance: 300000 },
|
||||
{ date: Date.today - 6, balance: 300000 },
|
||||
{ date: Date.today - 5, balance: 300000 },
|
||||
{ date: Date.today - 4, balance: 300000 },
|
||||
{ date: Date.today - 3, balance: 301900 },
|
||||
{ date: Date.today - 2, balance: 301900 },
|
||||
{ date: Date.today - 1, balance: 301900 },
|
||||
{ date: Date.today, balance: 302000 }
|
||||
]
|
||||
|
||||
|
||||
appraisals.each do |appraisal|
|
||||
Appraisal.find_or_create_by(
|
||||
account_id: account.id,
|
||||
date: appraisal[:date]
|
||||
) do |appraisal_record|
|
||||
appraisal_record.value = appraisal[:balance]
|
||||
appraisal_record.currency = "USD"
|
||||
end
|
||||
end
|
||||
|
||||
balances.each do |balance|
|
||||
AccountBalance.find_or_create_by(
|
||||
account_id: account.id,
|
||||
date: balance[:date]
|
||||
) do |balance_record|
|
||||
balance_record.balance = balance[:balance]
|
||||
balance_record.currency = "USD"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue