mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Dashboard View and Calculations (#521)
* Handle Turbo updates with tabs Fixes #491 * Add Filterable concern for controllers * Add trendline chart * Extract common UI to partials * Series refactor * Put placeholders for calculations in * Add classification generated column to account * Add basic net worth calculation * Add net worth tests * Get net worth graph working * Fix lint errors * Implement asset grouping query * Make trends and series more intuitive * Fully functional dashboard * Remove logging
This commit is contained in:
parent
680a91d807
commit
6f0e410684
37 changed files with 594 additions and 74 deletions
|
@ -5,7 +5,6 @@ class FamilyTest < ActiveSupport::TestCase
|
|||
@family = families(:dylan_family)
|
||||
|
||||
@family.accounts.each do |account|
|
||||
account.accountable = account.classification == "asset" ? account_other_assets(:one) : account_other_liabilities(:one)
|
||||
account.sync
|
||||
end
|
||||
end
|
||||
|
@ -78,4 +77,63 @@ class FamilyTest < ActiveSupport::TestCase
|
|||
|
||||
assert_equal expected_balances, @family.net_worth_series.data.map { |b| b[:value].amount }
|
||||
end
|
||||
|
||||
test "calculates balances by type" do
|
||||
verify_balances_by_type(
|
||||
period: Period.all,
|
||||
expected_asset_total: BigDecimal("25550"),
|
||||
expected_liability_total: BigDecimal("1000"),
|
||||
expected_asset_groups: {
|
||||
"Account::OtherAsset" => { end_balance: BigDecimal("550"), start_balance: BigDecimal("400"), allocation: 2.15 },
|
||||
"Account::Depository" => { end_balance: BigDecimal("25000"), start_balance: BigDecimal("25250"), allocation: 97.85 }
|
||||
},
|
||||
expected_liability_groups: {
|
||||
"Account::Credit" => { end_balance: BigDecimal("1000"), start_balance: BigDecimal("1040"), allocation: 100 }
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
test "calculates balances by type with a date range filter" do
|
||||
verify_balances_by_type(
|
||||
period: Period.new(name: "custom", date_range: 7.days.ago.to_date..2.days.ago.to_date),
|
||||
expected_asset_total: BigDecimal("26050"),
|
||||
expected_liability_total: BigDecimal("1000"),
|
||||
expected_asset_groups: {
|
||||
"Account::OtherAsset" => { end_balance: BigDecimal("550"), start_balance: BigDecimal("700"), allocation: 2.11 },
|
||||
"Account::Depository" => { end_balance: BigDecimal("25500"), start_balance: BigDecimal("24510"), allocation: 97.89 }
|
||||
},
|
||||
expected_liability_groups: {
|
||||
"Account::Credit" => { end_balance: BigDecimal("1000"), start_balance: BigDecimal("990"), allocation: 100 }
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def verify_balances_by_type(period:, expected_asset_total:, expected_liability_total:, expected_asset_groups:, expected_liability_groups:)
|
||||
result = @family.accounts.by_group(period)
|
||||
|
||||
asset_total = result[:asset][:total]
|
||||
liability_total = result[:liability][:total]
|
||||
|
||||
assert_equal expected_asset_total, asset_total
|
||||
assert_equal expected_liability_total, liability_total
|
||||
|
||||
asset_groups = result[:asset][:groups]
|
||||
liability_groups = result[:liability][:groups]
|
||||
|
||||
assert_equal expected_asset_groups.keys, asset_groups.keys
|
||||
expected_asset_groups.each do |type, expected_values|
|
||||
assert_equal expected_values[:end_balance], asset_groups[type][:end_balance]
|
||||
assert_equal expected_values[:start_balance], asset_groups[type][:start_balance]
|
||||
assert_equal expected_values[:allocation], asset_groups[type][:allocation]
|
||||
end
|
||||
|
||||
assert_equal expected_liability_groups.keys, liability_groups.keys
|
||||
expected_liability_groups.each do |type, expected_values|
|
||||
assert_equal expected_values[:end_balance], liability_groups[type][:end_balance]
|
||||
assert_equal expected_values[:start_balance], liability_groups[type][:start_balance]
|
||||
assert_equal expected_values[:allocation], liability_groups[type][:allocation]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue