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

Add start balance to manual accounts (#735)

* Add start_balance to accounts

* Add tests

* Cleanup

* Refactor code and add tests

* Update physical cash demo account to be manual

* Do not populate start_balance in migration

* Cleanup

* Review fixes

* Revert calc change

* Update app/models/exchange_rate.rb

Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
Signed-off-by: Jakub Kottnauer <jk@jakubkottnauer.com>

* Add test

* Fix syncable bug and update csv tests

---------

Signed-off-by: Jakub Kottnauer <jk@jakubkottnauer.com>
Co-authored-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
This commit is contained in:
Jakub Kottnauer 2024-05-16 21:57:21 +02:00 committed by GitHub
parent daf7ff8ef4
commit 3d9ff3ad2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 50 additions and 17 deletions

View file

@ -16,6 +16,10 @@ module Account::Syncable
calculator.calculate
self.balances.upsert_all(calculator.daily_balances, unique_by: :index_account_balances_on_account_id_date_currency_unique)
self.balances.where("date < ?", effective_start_date).delete_all
new_balance = calculator.daily_balances.select { |b| b[:currency] == self.currency }.last[:balance]
self.balance = new_balance
self.save!
update!(status: "ok", last_sync_date: Date.today)
rescue => e
update!(status: "error")