Skip to content

armgit / sure

Public Imported from GitHub
0

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.rb
index 32628f4aa6..9b41bcc0f8 100644
--- a/app/models/actual_import.rb
+++ b/app/models/actual_import.rb
@@ -28,7 +28,7 @@ class ActualImport < Import
date: 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 < Import
save!
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.strip
category_group = row[CATEGORY_GROUP_COLUMN].to_s.strip
diff --git a/config/brakeman.yml b/config/brakeman.yml
new file mode 100644
index 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:
+ - CheckEOLRails
diff --git a/test/fixtures/files/imports/actual.csv b/test/fixtures/files/imports/actual.csv
index 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,Reconc
Credit Card,2024-01-02,Coffee Shop,Morning coffee,Food,Coffee,-4.25,0,Cleared
Checking Account,2024-01-05,Employer,Monthly salary,Income,Paycheck,2500.00,0,Reconciled
Checking 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,Reconciled
diff --git a/test/models/actual_import_test.rb b/test/models/actual_import_test.rb
index 7cc0b3470c..d9758233bd 100644
--- a/test/models/actual_import_test.rb
+++ b/test/models/actual_import_test.rb
@@ -22,7 +22,7 @@ class ActualImportTest < ActiveSupport::TestCase
import.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)
end
test "generated rows combine category group and category" do
@@ -50,4 +50,52 @@ class ActualImportTest < ActiveSupport::TestCase
assert_equal "Housing", import.rows.order(:source_row_number).first.category
end
+
+ 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"
+ end
end