mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +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:
parent
b3f8ab78d9
commit
ad4de99f1a
9 changed files with 260 additions and 111 deletions
|
@ -1,16 +1,18 @@
|
|||
module Account::Syncable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
def sync_later
|
||||
AccountSyncJob.perform_later self
|
||||
def sync_later(start_date = nil)
|
||||
AccountSyncJob.perform_later(self, start_date)
|
||||
end
|
||||
|
||||
def sync
|
||||
def sync(start_date = nil)
|
||||
update!(status: "syncing")
|
||||
|
||||
sync_exchange_rates
|
||||
|
||||
calculator = Account::Balance::Calculator.new(self)
|
||||
calc_start_date = start_date - 1.day if start_date.present? && self.balance_on(start_date - 1.day).present?
|
||||
|
||||
calculator = Account::Balance::Calculator.new(self, { calc_start_date: })
|
||||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue