1
0
Fork 0
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:
Zach Gollwitzer 2024-02-20 09:07:55 -05:00 committed by GitHub
parent 298b50a909
commit b5b2d335fd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 512 additions and 167 deletions

View file

@ -0,0 +1,16 @@
class CreateValuations < ActiveRecord::Migration[7.2]
def change
create_table :valuations, id: :uuid do |t|
t.string :type, null: false
t.references :account, null: false, type: :uuid, foreign_key: { on_delete: :cascade }
t.date :date, null: false
t.decimal :value, precision: 19, scale: 4, null: false
t.string :currency, default: "USD", null: false
t.timestamps
end
# Since all dates are daily (no concept of time of day), limit account to 1 valuation per day
add_index :valuations, [ :account_id, :date ], unique: true
end
end

15
db/schema.rb generated
View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.2].define(version: 2024_02_12_150110) do
ActiveRecord::Schema[7.2].define(version: 2024_02_15_201527) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@ -206,7 +206,20 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_12_150110) do
t.index ["family_id"], name: "index_users_on_family_id"
end
create_table "valuations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "type", null: false
t.uuid "account_id", null: false
t.date "date", null: false
t.decimal "value", precision: 19, scale: 4, null: false
t.string "currency", default: "USD", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id", "date"], name: "index_valuations_on_account_id_and_date", unique: true
t.index ["account_id"], name: "index_valuations_on_account_id"
end
add_foreign_key "account_balances", "accounts", on_delete: :cascade
add_foreign_key "accounts", "families"
add_foreign_key "users", "families"
add_foreign_key "valuations", "accounts", on_delete: :cascade
end

View file

@ -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