trimming whitespace on import, fixed issue with units_in_pack column being too small
This commit is contained in:
@@ -220,6 +220,14 @@ def import_single_item(row, index, logger)
|
||||
success
|
||||
end
|
||||
|
||||
def trim_whitespace(row)
|
||||
row.map! do |value|
|
||||
trimmed = value.strip if not value.nil? # value.to_s.strip
|
||||
# puts "trimming '#{value}' to '#{trimmed}'"
|
||||
trimmed
|
||||
end
|
||||
end
|
||||
|
||||
def do_import(validate_only)
|
||||
begin
|
||||
input_file = ENV['INPUT']
|
||||
@@ -244,6 +252,7 @@ def do_import(validate_only)
|
||||
Item.transaction do
|
||||
CSV.foreach(path) do |row|
|
||||
if i != 1
|
||||
trim_whitespace(row)
|
||||
if import_single_item(row, i, logger) == false
|
||||
should_rollback = true
|
||||
end
|
||||
@@ -262,6 +271,7 @@ def do_import(validate_only)
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
puts "Import failed, please check the import log file for error details."
|
||||
logger.error "Error while importing: #{e}"
|
||||
end
|
||||
logger.info "Import done"
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class ChangeUnitsInPackColumnOnItems < ActiveRecord::Migration
|
||||
def change
|
||||
# t.decimal :units_in_pack, precision: 5, scale: 3
|
||||
change_column :items, :units_in_pack, :decimal, precision: 6, scale: 2
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user