mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Feature: Add "amount type" configuration column for CSV imports (#1947)
* Rough draft * Schema conflict update * Implement signage * Update system tests * Lint fixes
This commit is contained in:
parent
8cf077f28d
commit
c88fe2e3b2
21 changed files with 366 additions and 83 deletions
|
@ -277,6 +277,7 @@ module ImportInterfaceTest
|
|||
csv_data = "date,amount,name\n01/01/2024,1234.56,Test"
|
||||
import.update!(raw_file_str: csv_data)
|
||||
import.update!(
|
||||
date_col_label: "date",
|
||||
date_format: "%Y-%m-%d" # Does not match the raw CSV date, so rows will be invalid, but still generated
|
||||
)
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ class TradeImportTest < ActiveSupport::TestCase
|
|||
CSV
|
||||
|
||||
@import.update!(
|
||||
account: accounts(:depository),
|
||||
raw_file_str: import,
|
||||
date_col_label: "date",
|
||||
ticker_col_label: "ticker",
|
||||
|
@ -52,16 +53,11 @@ class TradeImportTest < ActiveSupport::TestCase
|
|||
|
||||
@import.reload
|
||||
|
||||
assert_difference [
|
||||
-> { Entry.count },
|
||||
-> { Trade.count }
|
||||
], 2 do
|
||||
assert_difference [
|
||||
-> { Security.count },
|
||||
-> { Account.count }
|
||||
], 1 do
|
||||
@import.publish
|
||||
end
|
||||
assert_difference -> { Entry.count } => 2,
|
||||
-> { Trade.count } => 2,
|
||||
-> { Security.count } => 1,
|
||||
-> { Account.count } => 1 do
|
||||
@import.publish
|
||||
end
|
||||
|
||||
assert_equal "complete", @import.status
|
||||
|
|
|
@ -68,4 +68,36 @@ class TransactionImportTest < ActiveSupport::TestCase
|
|||
|
||||
assert_equal "complete", @import.status
|
||||
end
|
||||
|
||||
test "imports transactions with separate type column for signage convention" do
|
||||
import = <<~CSV
|
||||
date,amount,amount_type
|
||||
01/01/2024,100,debit
|
||||
01/02/2024,200,credit
|
||||
01/03/2024,300,debit
|
||||
CSV
|
||||
|
||||
@import.update!(
|
||||
account: accounts(:depository),
|
||||
raw_file_str: import,
|
||||
date_col_label: "date",
|
||||
date_format: "%m/%d/%Y",
|
||||
amount_col_label: "amount",
|
||||
entity_type_col_label: "amount_type",
|
||||
amount_type_inflow_value: "debit",
|
||||
amount_type_strategy: "custom_column",
|
||||
signage_convention: nil # Explicitly set to nil to prove this is not needed
|
||||
)
|
||||
|
||||
@import.generate_rows_from_csv
|
||||
|
||||
@import.reload
|
||||
|
||||
assert_difference -> { Entry.count } => 3,
|
||||
-> { Transaction.count } => 3 do
|
||||
@import.publish
|
||||
end
|
||||
|
||||
assert_equal [ -100, 200, -300 ], @import.entries.map(&:amount)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,14 +21,14 @@ class ImportsTest < ApplicationSystemTestCase
|
|||
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
select "Date", from: "Date*"
|
||||
select "YYYY-MM-DD", from: "Date format"
|
||||
select "Amount", from: "Amount"
|
||||
select "Account", from: "Account (optional)"
|
||||
select "Name", from: "Name (optional)"
|
||||
select "Category", from: "Category (optional)"
|
||||
select "Tags", from: "Tags (optional)"
|
||||
select "Notes", from: "Notes (optional)"
|
||||
select "Date", from: "import[date_col_label]"
|
||||
select "YYYY-MM-DD", from: "import[date_format]"
|
||||
select "Amount", from: "import[amount_col_label]"
|
||||
select "Account", from: "import[account_col_label]"
|
||||
select "Name", from: "import[name_col_label]"
|
||||
select "Category", from: "import[category_col_label]"
|
||||
select "Tags", from: "import[tags_col_label]"
|
||||
select "Notes", from: "import[notes_col_label]"
|
||||
|
||||
click_on "Apply configuration"
|
||||
|
||||
|
@ -67,7 +67,12 @@ class ImportsTest < ApplicationSystemTestCase
|
|||
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
select "YYYY-MM-DD", from: "Date format"
|
||||
select "date", from: "import[date_col_label]"
|
||||
select "YYYY-MM-DD", from: "import[date_format]"
|
||||
select "qty", from: "import[qty_col_label]"
|
||||
select "ticker", from: "import[ticker_col_label]"
|
||||
select "price", from: "import[price_col_label]"
|
||||
select "account", from: "import[account_col_label]"
|
||||
|
||||
click_on "Apply configuration"
|
||||
|
||||
|
@ -100,6 +105,10 @@ class ImportsTest < ApplicationSystemTestCase
|
|||
|
||||
find('input[type="submit"][value="Upload CSV"]').click
|
||||
|
||||
select "type", from: "import[entity_type_col_label]"
|
||||
select "name", from: "import[name_col_label]"
|
||||
select "amount", from: "import[amount_col_label]"
|
||||
|
||||
click_on "Apply configuration"
|
||||
|
||||
click_on "Next step"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue