Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Add rows_to_skip config for transaction import

kasrae8216984a7b6
diff --git a/app/controllers/import/configurations_controller.rb b/app/controllers/import/configurations_controller.rb
index 85e6e402d6..ea4513668b 100644
--- a/app/controllers/import/configurations_controller.rb
+++ b/app/controllers/import/configurations_controller.rb
@@ -42,6 +42,7 @@ class Import::ConfigurationsController < ApplicationController
:signage_convention,
:amount_type_strategy,
:amount_type_inflow_value,
+ :rows_to_skip
)
end
end
diff --git a/app/models/import.rb b/app/models/import.rb
index 536209371a..6a5855ca01 100644
--- a/app/models/import.rb
+++ b/app/models/import.rb
@@ -36,6 +36,7 @@ class Import < ApplicationRecord
validates :col_sep, inclusion: { in: SEPARATORS.map(&:last) }
validates :signage_convention, inclusion: { in: SIGNAGE_CONVENTIONS }, allow_nil: true
validates :number_format, presence: true, inclusion: { in: NUMBER_FORMATS.keys }
+ validates :rows_to_skip, numericality: { greater_than_or_equal_to: 0 }
has_many :rows, dependent: :destroy
has_many :mappings, dependent: :destroy
@@ -248,7 +249,14 @@ class Import < ApplicationRecord
end
def parsed_csv
- @parsed_csv ||= self.class.parse_csv_str(raw_file_str, col_sep: col_sep)
+ return @parsed_csv if defined?(@parsed_csv)
+
+ csv_content = raw_file_str || ""
+ if rows_to_skip.to_i > 0
+ csv_content = csv_content.lines.drop(rows_to_skip).join
+ end
+
+ @parsed_csv = self.class.parse_csv_str(csv_content, col_sep: col_sep)
end
def sanitize_number(value)
diff --git a/app/views/import/configurations/_transaction_import.html.erb b/app/views/import/configurations/_transaction_import.html.erb
index 84301d6910..cc421c61b6 100644
--- a/app/views/import/configurations/_transaction_import.html.erb
+++ b/app/views/import/configurations/_transaction_import.html.erb
@@ -88,6 +88,9 @@
<% end %>
<%# Optional Fields %>
+ <%= form.number_field :rows_to_skip,
+ { label: "Skip first n rows", min: 0, step: 1, value: 0 } %>
+
<% unless import.account.present? %>
<%= form.select :account_col_label,
import.csv_headers,
diff --git a/db/migrate/20251226205942_add_rows_to_skip_to_imports.rb b/db/migrate/20251226205942_add_rows_to_skip_to_imports.rb
new file mode 100644
index 0000000000..3511cebf9e
--- /dev/null
+++ b/db/migrate/20251226205942_add_rows_to_skip_to_imports.rb
@@ -0,0 +1,5 @@
+class AddRowsToSkipToImports < ActiveRecord::Migration[7.2]
+ def change
+ add_column :imports, :rows_to_skip, :integer, default: 0, null: false
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 27adfde1e1..8f1bbc8b9d 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema[7.2].define(version: 2025_12_15_100443) do
+ActiveRecord::Schema[7.2].define(version: 2025_12_26_205942) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
enable_extension "plpgsql"
@@ -538,6 +538,7 @@ ActiveRecord::Schema[7.2].define(version: 2025_12_15_100443) do
t.string "exchange_operating_mic_col_label"
t.string "amount_type_strategy", default: "signed_amount"
t.string "amount_type_inflow_value"
+ t.integer "rows_to_skip", default: 0, null: false
t.index ["family_id"], name: "index_imports_on_family_id"
end