mirror of
https://github.com/we-promise/sure.git
synced 2026-05-24 13:04:56 +00:00
* Display multi-currency holdings correctly * Implement IBKR provider * Fix: Use historical exchange rate for historical prices * Add brokerage exchange rate for trades * Sync historical balances from IBKR * Add logos in activity history * Fix privacy mode blur in account view * Improve IBKR XML Flex report parser errors
37 lines
856 B
Ruby
37 lines
856 B
Ruby
class Transaction::ActivitySecurityPreloader
|
|
def initialize(records)
|
|
@records = Array(records)
|
|
end
|
|
|
|
def preload
|
|
transactions.each do |transaction|
|
|
transaction.set_preloaded_activity_security(securities_by_id[transaction.activity_security_id.to_s])
|
|
end
|
|
|
|
records
|
|
end
|
|
|
|
private
|
|
attr_reader :records
|
|
|
|
def transactions
|
|
@transactions ||= records.filter_map do |record|
|
|
case record
|
|
when Transaction
|
|
record
|
|
when Entry
|
|
record.transaction? ? record.entryable : nil
|
|
end
|
|
end
|
|
end
|
|
|
|
def securities_by_id
|
|
@securities_by_id ||= begin
|
|
security_ids = transactions.filter_map(&:activity_security_id).uniq
|
|
return {} if security_ids.empty?
|
|
|
|
Security.where(id: security_ids).index_by { |security| security.id.to_s }
|
|
end
|
|
end
|
|
end
|