1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-08-07 14:35:23 +02:00

Add partial account sync support (#653)

* Add partial account sync support

* Fix indentation

* Use historical balance as base when doing partial sync

* Simplify controller crud tests

* Fix linter errors
This commit is contained in:
Jakub Kottnauer 2024-04-24 21:55:52 +02:00 committed by GitHub
parent b3f8ab78d9
commit ad4de99f1a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 260 additions and 111 deletions

View file

@ -25,7 +25,7 @@ class Account::Balance::Calculator
prior_balance = current_balance
{ date: date, balance: current_balance, currency: @account.currency, updated_at: Time.current }
{ date:, balance: current_balance, currency: @account.currency, updated_at: Time.current }
end
@daily_balances = [
@ -92,11 +92,15 @@ class Account::Balance::Calculator
end
def implied_start_balance
if @calc_start_date > @account.effective_start_date
return @account.balance_on(@calc_start_date)
end
oldest_valuation_date = normalized_valuations.first&.dig("date")
oldest_transaction_date = normalized_transactions.first&.dig("date")
oldest_entry_date = [ oldest_valuation_date, oldest_transaction_date ].compact.min
if oldest_entry_date == oldest_valuation_date
if oldest_entry_date.present? && oldest_entry_date == oldest_valuation_date
oldest_valuation = normalized_valuations.find { |v| v["date"] == oldest_valuation_date }
oldest_valuation["value"].to_d
else