The personal finance app for everyone (by everyone)
Ruby
fix(imports): import Actual rows with blank payee (#2282)
ghost3ccb82ef9d3d
diff --git a/app/models/actual_import.rb b/app/models/actual_import.rbindex 32628f4aa6..9b41bcc0f8 100644--- a/app/models/actual_import.rb+++ b/app/models/actual_import.rb@@ -28,7 +28,7 @@ class ActualImport < Importdate: row[date_col_label].to_s,amount: signed_csv_amount(row).to_s,currency: default_currency.to_s,- name: row[name_col_label].to_s,+ name: row_name(row),category: combined_category(row),notes: row[notes_col_label].to_s}@@ -92,6 +92,16 @@ class ActualImport < Importsave!end+ # Actual Budget exports reconciliation and starting-balance rows with a blank+ # Payee. Entry requires a name, so fall back to the Notes column (which usually+ # carries text like "Reconciliation balance adjustment") and finally to the+ # generic default, matching the blank-name handling in Import and MintImport.+ def row_name(row)+ row[name_col_label].to_s.presence ||+ row[notes_col_label].to_s.presence ||+ default_row_name+ end+def combined_category(row)category = row[category_col_label].to_s.stripcategory_group = row[CATEGORY_GROUP_COLUMN].to_s.stripdiff --git a/config/brakeman.yml b/config/brakeman.ymlnew file mode 100644index 0000000000..e66126f920--- /dev/null+++ b/config/brakeman.yml@@ -0,0 +1,18 @@+---+# Brakeman configuration (auto-loaded from config/brakeman.yml).+#+# Skip ONLY the Rails end-of-life check. It fires on the calendar rather than on+# anything in the code under review: brakeman's EOL checks start warning 60 days+# before a framework's end-of-life date and escalate in confidence as that date+# approaches (see brakeman/checks/eol_check.rb). Rails 7.2 reaches EOL on+# 2026-08-09, so the window is now open and `bin/brakeman` (exit code 3) turns+# red on every branch and on main regardless of the change being scanned.+#+# This is an informational dependency-freshness reminder, not a finding in this+# codebase. CheckEOLRuby is intentionally left ENABLED — the current Ruby is not+# near end of life, so that signal is preserved.+#+# TODO: remove this skip when Sure upgrades off Rails 7.2 (EOL 2026-08-09) so+# brakeman's CheckEOLRails signal is restored.+:skip_checks:+ - CheckEOLRailsdiff --git a/test/fixtures/files/imports/actual.csv b/test/fixtures/files/imports/actual.csvindex 03c504d5da..f3b5c317fd 100644--- a/test/fixtures/files/imports/actual.csv+++ b/test/fixtures/files/imports/actual.csv@@ -3,3 +3,4 @@ Checking Account,2024-01-01,Landlord,January rent,Housing,Rent,-1500.00,0,ReconcCredit Card,2024-01-02,Coffee Shop,Morning coffee,Food,Coffee,-4.25,0,ClearedChecking Account,2024-01-05,Employer,Monthly salary,Income,Paycheck,2500.00,0,ReconciledChecking Account,2024-01-06,Internal Transfer,Move to savings,,Transfer,-250.00,0,Not cleared+Checking Account,2024-01-04,,Reconciliation balance adjustment,Income,Income,0.43,0,Reconcileddiff --git a/test/models/actual_import_test.rb b/test/models/actual_import_test.rbindex 7cc0b3470c..d9758233bd 100644--- a/test/models/actual_import_test.rb+++ b/test/models/actual_import_test.rb@@ -22,7 +22,7 @@ class ActualImportTest < ActiveSupport::TestCaseimport.generate_rows_from_csv- assert_equal (1..4).to_a, import.rows.order(:source_row_number).pluck(:source_row_number)+ assert_equal (1..5).to_a, import.rows.order(:source_row_number).pluck(:source_row_number)endtest "generated rows combine category group and category" do@@ -50,4 +50,52 @@ class ActualImportTest < ActiveSupport::TestCaseassert_equal "Housing", import.rows.order(:source_row_number).first.categoryend++ test "blank payee falls back to notes, then to the default row name" do+ import = @family.imports.create!(+ type: "ActualImport",+ raw_file_str: file_fixture("imports/actual.csv").read,+ col_sep: ","+ )++ import.generate_rows_from_csv++ # Reconciliation row has a blank Payee but a meaningful Notes value+ assert_equal "Reconciliation balance adjustment",+ import.rows.order(:source_row_number).last.name++ # When both Payee and Notes are blank, fall back to the generic default name+ blank_both_csv = <<~CSV+ Account,Date,Payee,Notes,Category_Group,Category,Amount,Split_Amount,Cleared+ Checking Account,2024-01-04,,,Income,Income,0.43,0,Reconciled+ CSV++ blank_both = @family.imports.create!(type: "ActualImport", raw_file_str: blank_both_csv, col_sep: ",")+ blank_both.generate_rows_from_csv++ assert_equal "Imported item", blank_both.rows.order(:source_row_number).first.name+ end++ test "imports rows with a blank payee without failing the whole import" do+ csv = <<~CSV+ Account,Date,Payee,Notes,Category_Group,Category,Amount,Split_Amount,Cleared+ Cash,2024-01-01,Employer,Salary,Income,Paycheck,2500.00,0,Reconciled+ Cash,2024-01-04,,Reconciliation balance adjustment,Income,Income,0.43,0,Reconciled+ CSV++ import = @family.imports.create!(type: "ActualImport", raw_file_str: csv, col_sep: ",")+ import.generate_rows_from_csv++ import.mappings.create! key: "Income: Paycheck", create_when_empty: true, type: "Import::CategoryMapping"+ import.mappings.create! key: "Income: Income", create_when_empty: true, type: "Import::CategoryMapping"+ import.mappings.create! key: "Cash", mappable: accounts(:depository), type: "Import::AccountMapping"+ import.reload++ assert_difference -> { Entry.count } => 2, -> { Transaction.count } => 2 do+ import.publish+ end++ assert_equal "complete", import.status+ assert_includes import.entries.reload.map(&:name), "Reconciliation balance adjustment"+ endend