mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 04:55:20 +02:00
perf(imports): Bulk import CSV trades (#2040)
This commit is contained in:
parent
5cf758bd03
commit
0a17b84566
1 changed files with 13 additions and 12 deletions
|
@ -3,7 +3,7 @@ class TradeImport < Import
|
||||||
transaction do
|
transaction do
|
||||||
mappings.each(&:create_mappable!)
|
mappings.each(&:create_mappable!)
|
||||||
|
|
||||||
rows.each do |row|
|
trades = rows.map do |row|
|
||||||
mapped_account = if account
|
mapped_account = if account
|
||||||
account
|
account
|
||||||
else
|
else
|
||||||
|
@ -16,21 +16,22 @@ class TradeImport < Import
|
||||||
exchange_operating_mic: row.exchange_operating_mic
|
exchange_operating_mic: row.exchange_operating_mic
|
||||||
)
|
)
|
||||||
|
|
||||||
entry = mapped_account.entries.build \
|
Account::Trade.new(
|
||||||
date: row.date_iso,
|
security: security,
|
||||||
amount: row.signed_amount,
|
qty: row.qty,
|
||||||
name: row.name,
|
|
||||||
currency: row.currency.presence || mapped_account.currency,
|
currency: row.currency.presence || mapped_account.currency,
|
||||||
entryable: Account::Trade.new(
|
price: row.price,
|
||||||
security: security,
|
entry: Account::Entry.new(
|
||||||
qty: row.qty,
|
account: mapped_account,
|
||||||
|
date: row.date_iso,
|
||||||
|
amount: row.signed_amount,
|
||||||
|
name: row.name,
|
||||||
currency: row.currency.presence || mapped_account.currency,
|
currency: row.currency.presence || mapped_account.currency,
|
||||||
price: row.price
|
import: self
|
||||||
),
|
),
|
||||||
import: self
|
)
|
||||||
|
|
||||||
entry.save!
|
|
||||||
end
|
end
|
||||||
|
Account::Trade.import!(trades, recursive: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue