1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-20 13:49:39 +02:00
Maybe/app/models/valuation.rb

21 lines
621 B
Ruby
Raw Normal View History

class Valuation < ApplicationRecord
belongs_to :account
after_commit :sync_account_balances, on: [ :create, :update ]
after_destroy :sync_account_balances_after_destroy
def trend(previous)
Trend.new(value, previous&.value)
end
private
def sync_account_balances_after_destroy
AccountBalanceSyncJob.perform_later(account_id: account_id, valuation_date: date, sync_type: "valuation", sync_action: "destroy")
end
def sync_account_balances
AccountBalanceSyncJob.perform_later(account_id: account_id, valuation_date: date, sync_type: "valuation", sync_action: "update")
end
end