1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-05 05:25:24 +02:00

Scaffold out Account Syncing (#474)

* 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

* Refactor series logic

* Scaffold out basic sync process for accounts

* Fix tests
This commit is contained in:
Zach Gollwitzer 2024-02-22 11:35:06 -05:00 committed by GitHub
parent b5b2d335fd
commit 7e324f1b53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 328 additions and 185 deletions

View file

@ -0,0 +1,5 @@
class RemoveValuationType < ActiveRecord::Migration[7.2]
def change
remove_column :valuations, :type, :string
end
end

View file

@ -0,0 +1,5 @@
class AddStatusToAccount < ActiveRecord::Migration[7.2]
def change
add_column :accounts, :status, :string, default: "OK"
end
end

4
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_15_201527) do
ActiveRecord::Schema[7.2].define(version: 2024_02_22_144849) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@ -78,6 +78,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_15_201527) do
t.string "original_currency", default: "USD"
t.decimal "converted_balance", precision: 19, scale: 4, default: "0.0"
t.string "converted_currency", default: "USD"
t.string "status", default: "OK"
t.index ["accountable_type"], name: "index_accounts_on_accountable_type"
t.index ["family_id"], name: "index_accounts_on_family_id"
end
@ -207,7 +208,6 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_15_201527) do
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

View file

@ -32,16 +32,15 @@ account = Account.create_or_find_by(name: "Seed Property Account", accountable:
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 }
valuations = [
{ date: Date.today - 30, value: 300000 },
{ date: Date.today - 22, value: 300700 },
{ date: Date.today - 17, value: 301400 },
{ date: Date.today - 10, value: 300000 },
{ date: Date.today - 3, value: 301900 }
]
# In prod, this would be calculated from the current balance and the appraisals with a background job
# Hardcoded for readability
# Represent system-generated "Balances" at various dates, based on valuations
balances = [
{ date: Date.today - 30, balance: 300000 },
{ date: Date.today - 29, balance: 300000 },
@ -73,17 +72,16 @@ balances = [
{ date: Date.today - 3, balance: 301900 },
{ date: Date.today - 2, balance: 301900 },
{ date: Date.today - 1, balance: 301900 },
{ date: Date.today, balance: 302000 }
{ date: Date.today, balance: current_balance }
]
appraisals.each do |appraisal|
Appraisal.find_or_create_by(
valuations.each do |valuation|
Valuation.find_or_create_by(
account_id: account.id,
date: appraisal[:date]
) do |appraisal_record|
appraisal_record.value = appraisal[:balance]
appraisal_record.currency = "USD"
date: valuation[:date]
) do |valuation_record|
valuation_record.value = valuation[:value]
valuation_record.currency = "USD"
end
end
@ -93,6 +91,5 @@ balances.each do |balance|
date: balance[:date]
) do |balance_record|
balance_record.balance = balance[:balance]
balance_record.currency = "USD"
end
end