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

Multi-currency part 1 (#542)

* Add family snapshots table

* Add snapshot method, clean up family expected results

* Remove old sync trigger
This commit is contained in:
Zach Gollwitzer 2024-03-11 16:32:13 -04:00 committed by GitHub
parent 1cdf5ea6a7
commit c60ddaec1d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 169 additions and 141 deletions

View file

@ -0,0 +1,32 @@
date_offset,net_worth,assets,liabilities,depositories,investments,loans,credits,properties,vehicles,other_assets,other_liabilities
-30,24610,25650,1040,25250,0,0,1040,0,0,400,0
-29,25195,26135,940,25735,0,0,940,0,0,400,0
-28,25195,26135,940,25735,0,0,940,0,0,400,0
-27,25195,26135,940,25735,0,0,940,0,0,400,0
-26,25195,26135,940,25735,0,0,940,0,0,400,0
-25,24445,25385,940,24985,0,0,940,0,0,400,0
-24,24445,25385,940,24985,0,0,940,0,0,400,0
-23,24445,25385,940,24985,0,0,940,0,0,400,0
-22,25520,26460,940,26060,0,0,940,0,0,400,0
-21,25520,26460,940,26060,0,0,940,0,0,400,0
-20,25520,26460,940,26060,0,0,940,0,0,400,0
-19,25520,26460,940,26060,0,0,940,0,0,400,0
-18,23520,24460,940,24060,0,0,940,0,0,400,0
-17,23520,24460,940,24060,0,0,940,0,0,400,0
-16,23520,24460,940,24060,0,0,940,0,0,400,0
-15,23480,24440,960,24040,0,0,960,0,0,400,0
-14,23480,24440,960,24040,0,0,960,0,0,400,0
-13,23480,24440,960,24040,0,0,960,0,0,400,0
-12,24220,25210,990,24510,0,0,990,0,0,700,0
-11,24220,25210,990,24510,0,0,990,0,0,700,0
-10,24220,25210,990,24510,0,0,990,0,0,700,0
-9,24220,25210,990,24510,0,0,990,0,0,700,0
-8,24220,25210,990,24510,0,0,990,0,0,700,0
-7,24220,25210,990,24510,0,0,990,0,0,700,0
-6,24220,25210,990,24510,0,0,990,0,0,700,0
-5,24400,25400,1000,24700,0,0,1000,0,0,700,0
-4,24250,25250,1000,24700,0,0,1000,0,0,550,0
-3,25050,26050,1000,25500,0,0,1000,0,0,550,0
-2,25050,26050,1000,25500,0,0,1000,0,0,550,0
-1,25050,26050,1000,25500,0,0,1000,0,0,550,0
0,24550,25550,1000,25000,0,0,1000,0,0,550,0
1 date_offset net_worth assets liabilities depositories investments loans credits properties vehicles other_assets other_liabilities
2 -30 24610 25650 1040 25250 0 0 1040 0 0 400 0
3 -29 25195 26135 940 25735 0 0 940 0 0 400 0
4 -28 25195 26135 940 25735 0 0 940 0 0 400 0
5 -27 25195 26135 940 25735 0 0 940 0 0 400 0
6 -26 25195 26135 940 25735 0 0 940 0 0 400 0
7 -25 24445 25385 940 24985 0 0 940 0 0 400 0
8 -24 24445 25385 940 24985 0 0 940 0 0 400 0
9 -23 24445 25385 940 24985 0 0 940 0 0 400 0
10 -22 25520 26460 940 26060 0 0 940 0 0 400 0
11 -21 25520 26460 940 26060 0 0 940 0 0 400 0
12 -20 25520 26460 940 26060 0 0 940 0 0 400 0
13 -19 25520 26460 940 26060 0 0 940 0 0 400 0
14 -18 23520 24460 940 24060 0 0 940 0 0 400 0
15 -17 23520 24460 940 24060 0 0 940 0 0 400 0
16 -16 23520 24460 940 24060 0 0 940 0 0 400 0
17 -15 23480 24440 960 24040 0 0 960 0 0 400 0
18 -14 23480 24440 960 24040 0 0 960 0 0 400 0
19 -13 23480 24440 960 24040 0 0 960 0 0 400 0
20 -12 24220 25210 990 24510 0 0 990 0 0 700 0
21 -11 24220 25210 990 24510 0 0 990 0 0 700 0
22 -10 24220 25210 990 24510 0 0 990 0 0 700 0
23 -9 24220 25210 990 24510 0 0 990 0 0 700 0
24 -8 24220 25210 990 24510 0 0 990 0 0 700 0
25 -7 24220 25210 990 24510 0 0 990 0 0 700 0
26 -6 24220 25210 990 24510 0 0 990 0 0 700 0
27 -5 24400 25400 1000 24700 0 0 1000 0 0 700 0
28 -4 24250 25250 1000 24700 0 0 1000 0 0 550 0
29 -3 25050 26050 1000 25500 0 0 1000 0 0 550 0
30 -2 25050 26050 1000 25500 0 0 1000 0 0 550 0
31 -1 25050 26050 1000 25500 0 0 1000 0 0 550 0
32 0 24550 25550 1000 25000 0 0 1000 0 0 550 0

View file

@ -1,4 +1,5 @@
require "test_helper"
require "csv"
class FamilyTest < ActiveSupport::TestCase
def setup
@ -48,6 +49,45 @@ class FamilyTest < ActiveSupport::TestCase
assert_equal BigDecimal("24550"), @family.net_worth
end
test "should calculate snapshot correctly" do
# See this Google Sheet for calculations and expected results for dylan_family:
# https://docs.google.com/spreadsheets/d/18LN5N-VLq4b49Mq1fNwF7_eBiHSQB46qQduRtdAEN98/edit?usp=sharing
expected_snapshots = CSV.read("test/fixtures/family/expected_snapshots.csv", headers: true).map do |row|
{
"date" => (Date.current + row["date_offset"].to_i.days).to_date,
"net_worth" => row["net_worth"],
"assets" => row["assets"],
"liabilities" => row["liabilities"]
}
end
asset_series = @family.snapshot[:asset_series]
liability_series = @family.snapshot[:liability_series]
net_worth_series = @family.snapshot[:net_worth_series]
assert_equal expected_snapshots.count, asset_series.data.count
assert_equal expected_snapshots.count, liability_series.data.count
assert_equal expected_snapshots.count, net_worth_series.data.count
expected_snapshots.each_with_index do |row, index|
expected = {
date: row["date"],
assets: row["assets"].to_d,
liabilities: row["liabilities"].to_d,
net_worth: row["net_worth"].to_d
}
actual = {
date: asset_series.data[index][:date],
assets: asset_series.data[index][:value].amount,
liabilities: liability_series.data[index][:value].amount,
net_worth: net_worth_series.data[index][:value].amount
}
assert_equal expected, actual
end
end
test "should exclude disabled accounts from calculations" do
assets_before = @family.assets
liabilities_before = @family.liabilities
@ -64,42 +104,6 @@ class FamilyTest < ActiveSupport::TestCase
assert_equal net_worth_before - disabled_checking.balance + disabled_cc.balance, @family.net_worth
end
test "calculates asset series" do
# Sum of expected balances for all asset accounts in balance_calculator_test.rb
expected_balances = [
25650, 26135, 26135, 26135, 26135, 25385, 25385, 25385, 26460, 26460,
26460, 26460, 24460, 24460, 24460, 24440, 24440, 24440, 25210, 25210,
25210, 25210, 25210, 25210, 25210, 25400, 25250, 26050, 26050, 26050,
25550
].map(&:to_d)
assert_equal expected_balances, @family.asset_series.data.map { |b| b[:value].amount }
end
test "calculates liability series" do
# Sum of expected balances for all liability accounts in balance_calculator_test.rb
expected_balances = [
1040, 940, 940, 940, 940, 940, 940, 940, 940, 940,
940, 940, 940, 940, 940, 960, 960, 960, 990, 990,
990, 990, 990, 990, 990, 1000, 1000, 1000, 1000, 1000,
1000
].map(&:to_d)
assert_equal expected_balances, @family.liability_series.data.map { |b| b[:value].amount }
end
test "calculates net worth" do
# Net difference between asset and liability series above
expected_balances = [
24610, 25195, 25195, 25195, 25195, 24445, 24445, 24445, 25520, 25520,
25520, 25520, 23520, 23520, 23520, 23480, 23480, 23480, 24220, 24220,
24220, 24220, 24220, 24220, 24220, 24400, 24250, 25050, 25050, 25050,
24550
].map(&:to_d)
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,