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
|
success
|
||||||
end
|
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)
|
def do_import(validate_only)
|
||||||
begin
|
begin
|
||||||
input_file = ENV['INPUT']
|
input_file = ENV['INPUT']
|
||||||
@@ -244,6 +252,7 @@ def do_import(validate_only)
|
|||||||
Item.transaction do
|
Item.transaction do
|
||||||
CSV.foreach(path) do |row|
|
CSV.foreach(path) do |row|
|
||||||
if i != 1
|
if i != 1
|
||||||
|
trim_whitespace(row)
|
||||||
if import_single_item(row, i, logger) == false
|
if import_single_item(row, i, logger) == false
|
||||||
should_rollback = true
|
should_rollback = true
|
||||||
end
|
end
|
||||||
@@ -262,6 +271,7 @@ def do_import(validate_only)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
puts "Import failed, please check the import log file for error details."
|
||||||
logger.error "Error while importing: #{e}"
|
logger.error "Error while importing: #{e}"
|
||||||
end
|
end
|
||||||
logger.info "Import done"
|
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