Add rows_to_skip config for transaction import

This commit is contained in:
kasra
2025-12-27 02:21:28 +03:30
parent 33fdd589e4
commit e8216984a7
5 changed files with 20 additions and 2 deletions

View File

@@ -42,6 +42,7 @@ class Import::ConfigurationsController < ApplicationController
:signage_convention,
:amount_type_strategy,
:amount_type_inflow_value,
:rows_to_skip
)
end
end

View File

@@ -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)

View File

@@ -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,

View File

@@ -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

3
db/schema.rb generated
View File

@@ -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