The personal finance app for everyone
import: Bulk import transaction data. (#1962)
Joseph Hob41897b5e5b2
diff --git a/Gemfile b/Gemfileindex 86027d7f..7ff6348f 100644--- a/Gemfile+++ b/Gemfile@@ -58,6 +58,7 @@ gem "intercom-rails"gem "plaid"gem "rotp", "~> 6.3"gem "rqrcode", "~> 2.2"+gem "activerecord-import"group :development, :test dogem "debug", platforms: %i[mri windows]diff --git a/Gemfile.lock b/Gemfile.lockindex 6d0899c1..7ae44280 100644--- a/Gemfile.lock+++ b/Gemfile.lock@@ -61,6 +61,8 @@ GEMactivemodel (= 7.2.2.1)activesupport (= 7.2.2.1)timeout (>= 0.4.0)+ activerecord-import (2.1.0)+ activerecord (>= 4.2)activestorage (7.2.2.1)actionpack (= 7.2.2.1)activejob (= 7.2.2.1)@@ -529,6 +531,7 @@ PLATFORMSx86_64-linux-muslDEPENDENCIES+ activerecord-importaws-sdk-s3 (~> 1.177.0)bcrypt (~> 3.1)benchmark-ipsdiff --git a/app/models/transaction_import.rb b/app/models/transaction_import.rbindex 2bb9d4d5..cf3f6e12 100644--- a/app/models/transaction_import.rb+++ b/app/models/transaction_import.rb@@ -3,7 +3,7 @@ class TransactionImport < Importtransaction domappings.each(&:create_mappable!)- rows.each do |row|+ transactions = rows.map do |row|mapped_account = if accountaccountelse@@ -13,17 +13,22 @@ class TransactionImport < Importcategory = mappings.categories.mappable_for(row.category)tags = row.tags_list.map { |tag| mappings.tags.mappable_for(tag) }.compact- entry = mapped_account.entries.build \- date: row.date_iso,- amount: row.signed_amount,- name: row.name,- currency: row.currency,- notes: row.notes,- entryable: Account::Transaction.new(category: category, tags: tags),- import: self-- entry.save!+ Account::Transaction.new(+ category: category,+ tags: tags,+ entry: Account::Entry.new(+ account: mapped_account,+ date: row.date_iso,+ amount: row.signed_amount,+ name: row.name,+ currency: row.currency,+ notes: row.notes,+ import: self+ )+ )end++ Account::Transaction.import!(transactions, recursive: true)endend