mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-02 20:15:22 +02:00
CSV Imports Overhaul (Transactions, Trades, Accounts, and Mint import support) (#1209)
* Remove stale 1.0 import logic and model * Fresh start * Checkpoint before removing nav * First working prototype * Add trade, account, and mint import flows * Basic working version with tests * System tests for each import type * Clean up mappings flow * Clean up PR, refactor stale code, tests * Add back row validations * Row validations * Fix import job test * Fix import navigation * Fix mint import configuration form * Currency preset for new accounts
This commit is contained in:
parent
23786b444a
commit
398b246965
103 changed files with 2420 additions and 1689 deletions
46
app/models/transaction_import.rb
Normal file
46
app/models/transaction_import.rb
Normal file
|
@ -0,0 +1,46 @@
|
|||
class TransactionImport < Import
|
||||
def import!
|
||||
transaction do
|
||||
mappings.each(&:create_mappable!)
|
||||
|
||||
rows.each do |row|
|
||||
account = mappings.accounts.mappable_for(row.account)
|
||||
category = mappings.categories.mappable_for(row.category)
|
||||
tags = row.tags_list.map { |tag| mappings.tags.mappable_for(tag) }.compact
|
||||
|
||||
entry = account.entries.build \
|
||||
date: row.date_iso,
|
||||
amount: row.signed_amount,
|
||||
name: row.name,
|
||||
currency: row.currency,
|
||||
entryable: Account::Transaction.new(category: category, tags: tags, notes: row.notes),
|
||||
import: self
|
||||
|
||||
entry.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def required_column_keys
|
||||
%i[date amount]
|
||||
end
|
||||
|
||||
def column_keys
|
||||
%i[date amount name currency category tags account notes]
|
||||
end
|
||||
|
||||
def mapping_steps
|
||||
[ Import::CategoryMapping, Import::TagMapping, Import::AccountMapping ]
|
||||
end
|
||||
|
||||
def csv_template
|
||||
template = <<-CSV
|
||||
date*,amount*,name,currency,category,tags,account,notes
|
||||
05/15/2024,-45.99,Grocery Store,USD,Food,groceries|essentials,Checking Account,Monthly grocery run
|
||||
05/16/2024,1500.00,Salary,,Income,,Main Account,
|
||||
05/17/2024,-12.50,Coffee Shop,,,coffee,,
|
||||
CSV
|
||||
|
||||
CSV.parse(template, headers: true)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue