mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
Net worth calculation (#508)
* Add classification generated column to account * Add basic net worth calculation * Add net worth tests * Fix lint errors
This commit is contained in:
parent
19f15e9391
commit
facd74f733
12 changed files with 156 additions and 40 deletions
18
db/migrate/20240302145715_add_classification_to_accounts.rb
Normal file
18
db/migrate/20240302145715_add_classification_to_accounts.rb
Normal file
|
@ -0,0 +1,18 @@
|
|||
class AddClassificationToAccounts < ActiveRecord::Migration[7.2]
|
||||
def change
|
||||
change_table :accounts do |t|
|
||||
t.virtual(
|
||||
:classification,
|
||||
type: :string,
|
||||
stored: true,
|
||||
as: <<-SQL
|
||||
CASE
|
||||
WHEN accountable_type IN ('Account::Loan', 'Account::Credit', 'Account::OtherLiability')
|
||||
THEN 'liability'
|
||||
ELSE 'asset'
|
||||
END
|
||||
SQL
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
3
db/schema.rb
generated
3
db/schema.rb
generated
|
@ -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_27_142457) do
|
||||
ActiveRecord::Schema[7.2].define(version: 2024_03_02_145715) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
|
@ -79,6 +79,7 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_27_142457) do
|
|||
t.decimal "converted_balance", precision: 19, scale: 4, default: "0.0"
|
||||
t.string "converted_currency", default: "USD"
|
||||
t.string "status", default: "OK"
|
||||
t.virtual "classification", type: :string, as: "\nCASE\n WHEN ((accountable_type)::text = ANY ((ARRAY['Account::Loan'::character varying, 'Account::Credit'::character varying, 'Account::OtherLiability'::character varying])::text[])) THEN 'liability'::text\n ELSE 'asset'::text\nEND", stored: true
|
||||
t.index ["accountable_type"], name: "index_accounts_on_accountable_type"
|
||||
t.index ["family_id"], name: "index_accounts_on_family_id"
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue