Add start balance to manual accounts #735
Reference in New Issue
Block a user
Delete Branch "manual-account-start-balance"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR makes
balanceof manual accounts be automatically updated whenever a new valuation or a transaction is added to that account. In this first iteration, the solution "hijacks" the existing sync flow by first computing the correct current balance which is then treated as the "source of truth" in the rest of the sync (as if it was an account connected to a 3rd party provider).Current balance of a manual account is calculated as follows:
start_balanceif no valuation existsChanges
A new
accounts.start_balancecolumn has been added. I have considered making the migration populate the column for all accounts (as we only have manual accounts at the time of running the migration) but then to be consistent I would also have to change all of the seed data to create manual accounts, which doesn't sound like something we'd like to do. Happy to discuss this further.All newly created accounts will be manual by default as we don't have support for connected accounts yet.
Next steps
dateset in the future. This means that accounts need to be synced periodically to make sure the balance is up to date every day the user opens Maybe. Somewhat similar to the issue https://github.com/maybe-finance/maybe/issues/724 and can be fixed the same way.account.start_balance.nil?. In the future it would be nicer to check if a provider connection exists for the account, but we're not quite there yet.@zachgoll After this is reviewed I will need some help with updating the Google Sheet to include the new manual account fixtures.
@jakubkottnauer will take a look this afternoon!
@jakubkottnauer thanks for the work on this! I've addressed some of the various questions below along with some overall thoughts:
We do have some designs, I'll be getting them out for dev soon!
Should future dates be valid? I know we're not enforcing this currently but it may be a good idea to set a max date of
Date.currentfor valuations and transactions.There are some designs in the works to distinguish between the two, but I'm starting to think that we should simply overwrite the existing sync process and tests and assume that all accounts are manual for now. I'm completely fine deleting the existing sync logic and making this the new "base case" until we have connected accounts to work with. We can always go back in source control to find the "connected account logic". For now, I think it will be a lot simpler to deal with concrete flows rather than trying to design for the future.
Off the top of my head, I think the pieces that we'd need to address would be:
Strategy
In my head, a "start balance" is ultimately the same thing as a
Valuation. It has a monetary value + date.Rather than introducing a new DB field, I think we can just use the "oldest Valuation" as our start balance. When a user creates an account, we can ask them for this information and our system will automatically create the
Valuation:Valuationequal to the date + amount input)If we did this, I think we'd be able to keep almost all of our existing balance calculator logic. The only thing that would then change would be this line:
5ed2c47c20/app/models/account/balance/calculator.rb (L34)We would then need to make sure that on every sync,
@account.balanceis updated to reflect the calculated series.Thank you for the review! I'll incorporate the changes you've suggested, making manual accounts the "base case" for now 👍
Some other apps I have used allow future transactions, though I don't see much value in allowing future valuations. And if we won't be allowing those, maybe it makes not to allow transactions either for consistency 😄 Up to you!
I like the proposed solution, I'll make the change today/tomorrow
@jakubkottnauer I think for now we can enforce a max date of
Date.currentfor simplicity. I could see a case for future dates for both, but it's not worth the complexity right now:@zachgoll I've implemented the changes, seems to work well
Looks good! Can you update the tests to expect this new convention? Will get it merged after those pass.
@@ -18,5 +18,12 @@ class ExchangeRate < ApplicationRecorddef get_rate_series(from, to, date_range)@zachgoll I've pushed a few new tests. Can you help out with updating the CSVs?
@jakubkottnauer here is the link to the Google sheet that I've been using to visualize the test cases:
https://docs.google.com/spreadsheets/d/18LN5N-VLq4b49Mq1fNwF7_eBiHSQB46qQduRtdAEN98/edit?usp=sharing
I'll go ahead and get this updated after this PR is merged. But for now, I think all we need to do is update the final row in each of these CSVs:
daf7ff8ef4/test/fixtures/family/expected_snapshots.csv (L32)daf7ff8ef4/test/fixtures/account/expected_balances.csv (L32)@zachgoll All tests are green now 😄
Awesome, looks great! Thanks for the work on this!