include index in parse
This commit is contained in:
parent
f7371976ca
commit
e8ae076cf4
5 changed files with 20 additions and 12 deletions
|
@ -136,10 +136,10 @@ module FoodsoftArticleImport
|
|||
}
|
||||
errors.compact!
|
||||
if errors.count > 0
|
||||
yield article, errors.join("\n")
|
||||
yield article, errors.join("\n"), linenum
|
||||
else
|
||||
# outlisting not used by supplier
|
||||
yield article, nil
|
||||
yield article, nil, linenum
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -56,7 +56,15 @@ module FoodsoftArticleImport
|
|||
encoding = opts[:encoding] || OPTIONS[:encoding]
|
||||
col_sep = opts[:col_sep] || OPTIONS[:col_sep]
|
||||
self.load_codes(custom_file)
|
||||
CSV.foreach(file, {col_sep: col_sep, encoding: encoding, headers: true}) do |row|
|
||||
CSV.foreach(file, {col_sep: col_sep, encoding: encoding, headers: true}).with_index(1) do |row, i|
|
||||
puts "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "______________" + "
|
||||
" + "#{i}#{row}" + "
|
||||
" + "______________"+ "
|
||||
" + "______________"+ "
|
||||
" + "______________"
|
||||
# check if the line is empty
|
||||
unless row[0] == "" || row[0].nil?
|
||||
article = {
|
||||
|
@ -86,9 +94,9 @@ module FoodsoftArticleImport
|
|||
# N=neu, A=Änderung, X=ausgelistet, R=Restbestand,
|
||||
# V=vorübergehend ausgelistet, W=wiedergelistet
|
||||
elsif row[1] == "X" || row[1] == "V"
|
||||
yield article, :outlisted
|
||||
yield article, :outlisted, i
|
||||
else
|
||||
yield article, nil
|
||||
yield article, nil, i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -24,7 +24,7 @@ module FoodsoftArticleImport
|
|||
|
||||
file.set_encoding(opts[:encoding] || OPTIONS[:encoding])
|
||||
col_sep = opts[:col_sep] || OPTIONS[:col_sep]
|
||||
CSV.new(file, {col_sep: col_sep, :headers => false}).each do |row|
|
||||
CSV.new(file, {col_sep: col_sep, :headers => false}).each.with_index(1) do |row, i|
|
||||
|
||||
# Set manufacturer
|
||||
if row[1] == "-"
|
||||
|
@ -86,7 +86,7 @@ module FoodsoftArticleImport
|
|||
raise "Fehler: Einheit, Preis und MwSt. müssen gegeben sein: #{article.inspect}"
|
||||
end
|
||||
|
||||
yield article, nil
|
||||
yield article, nil, i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -20,7 +20,7 @@ module FoodsoftArticleImport
|
|||
Nokogiri::XML::ParseOptions::NONET +
|
||||
Nokogiri::XML::ParseOptions::COMPACT # do not modify doc!
|
||||
)
|
||||
doc.search('product').each do |row|
|
||||
doc.search('product').each.with_index(1) do |row, i|
|
||||
# create a new article
|
||||
unit = row.search('eenheid').text
|
||||
unit = case(unit)
|
||||
|
@ -52,7 +52,7 @@ module FoodsoftArticleImport
|
|||
:deposit => deposit,
|
||||
:category => category}
|
||||
|
||||
yield article, (row.search('status') == 'Actief' ? :outlisted : nil)
|
||||
yield article, (row.search('status') == 'Actief' ? :outlisted : nil), i
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ module FoodsoftArticleImport::Foodsoft
|
|||
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)
|
||||
|
||||
header_row = true
|
||||
ss.sheet(0).each do |row|
|
||||
ss.sheet(0).each.with_index(1) do |row, i|
|
||||
# skip first header row
|
||||
if header_row
|
||||
header_row = false
|
||||
|
@ -45,9 +45,9 @@ module FoodsoftArticleImport::Foodsoft
|
|||
article.merge!(:deposit => row[9]) unless row[9].nil?
|
||||
article[:number].blank? and ArticleImport.generate_number(article)
|
||||
if row[6].nil? || row[7].nil? or row[8].nil?
|
||||
yield article, "Error: unit, price and tax must be entered"
|
||||
yield article, "Error: unit, price and tax must be entered", i
|
||||
else
|
||||
yield article, (row[0]=='x' ? :outlisted : nil)
|
||||
yield article, (row[0]=='x' ? :outlisted : nil), i
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue