gehirnpups
This commit is contained in:
parent
0ca60f53a6
commit
7a058847eb
3 changed files with 67 additions and 50 deletions
|
@ -52,10 +52,14 @@ module FoodsoftArticleImport
|
|||
# (sub)categories are in first two content cells - assume if there's a price it's a product
|
||||
if row[:number].blank? && row[:unit_price].blank?
|
||||
category = row[:name]
|
||||
yield nil, nil, linenum
|
||||
next
|
||||
end
|
||||
# skip products without a number
|
||||
row[:number].blank? and next
|
||||
if row[:number].blank?
|
||||
yield nil, nil, linenum
|
||||
next
|
||||
end
|
||||
# extract name and unit
|
||||
errors = []
|
||||
notes = []
|
||||
|
@ -67,7 +71,10 @@ module FoodsoftArticleImport
|
|||
manufacturer = nil
|
||||
prod_category = nil
|
||||
RES_PARSE_UNIT.each do |re|
|
||||
m=name.match(re) or next
|
||||
m=name.match(re)
|
||||
unless m
|
||||
yield nil, nil, linenum
|
||||
end
|
||||
unit = self.normalize_unit(m[3])
|
||||
name = name.sub(re, '').sub(/\(\s*\)\s*$/,'').sub(/\s+/, ' ').sub(/\.\s*$/, '').strip
|
||||
break
|
||||
|
|
|
@ -33,58 +33,64 @@ module FoodsoftArticleImport
|
|||
end
|
||||
|
||||
# check if the line is empty
|
||||
next if row[1].blank? || row[1] == "-"
|
||||
unless row[1].blank? || row[1] == "-"
|
||||
|
||||
# Split string and remove beginning "
|
||||
matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main])
|
||||
# Split string and remove beginning "
|
||||
matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main])
|
||||
|
||||
next if matched.nil?
|
||||
if matched.nil?
|
||||
puts "No regular article data for #{row[1]}: #{row[2]}"
|
||||
yield nil, nil, nil
|
||||
else
|
||||
name, units, price_high, price_low = matched.captures
|
||||
|
||||
name, units, price_high, price_low = matched.captures
|
||||
# Try to get origin
|
||||
matched_name = name.match(REGEX[:origin])
|
||||
if matched_name
|
||||
name, origin = matched_name.captures
|
||||
else
|
||||
name, origin = name.gsub(/\s{2,}/, ""), nil
|
||||
end
|
||||
|
||||
# Try to get origin
|
||||
matched_name = name.match(REGEX[:origin])
|
||||
if matched_name
|
||||
name, origin = matched_name.captures
|
||||
else
|
||||
name, origin = name.gsub(/\s{2,}/, ""), nil
|
||||
# Manufacturer
|
||||
if name.match(/^[A-Za-z]{2,3}\s{1}/)
|
||||
name.gsub!(/^[A-Za-z]{2,3}\s{1}/, "")
|
||||
manufacturer = global_manufacturer
|
||||
end
|
||||
|
||||
|
||||
# Get unit quantities
|
||||
units = units.split("x")
|
||||
if units.size == 2
|
||||
unit_quantity = units.first
|
||||
unit = units.last
|
||||
else
|
||||
unit_quantity = 1
|
||||
unit = units.first
|
||||
end
|
||||
|
||||
article = {
|
||||
:number => row[1],
|
||||
:name => name,
|
||||
:origin => origin,
|
||||
:manufacturer => manufacturer,
|
||||
:unit_quantity => unit_quantity,
|
||||
:unit => unit,
|
||||
:price => price_low, # Inklusive Rabattstufe von 10%
|
||||
:tax => 0.0 # Tax is included
|
||||
}
|
||||
|
||||
# test, if neccecary attributes exists
|
||||
if article[:unit].nil? || article[:price].nil? || article[:unit_quantity].nil?
|
||||
raise "Fehler: Einheit, Preis und MwSt. müssen gegeben sein: #{article.inspect}"
|
||||
end
|
||||
|
||||
yield article, nil, i
|
||||
end
|
||||
end
|
||||
|
||||
# Manufacturer
|
||||
if name.match(/^[A-Za-z]{2,3}\s{1}/)
|
||||
name.gsub!(/^[A-Za-z]{2,3}\s{1}/, "")
|
||||
manufacturer = global_manufacturer
|
||||
end
|
||||
|
||||
|
||||
# Get unit quantities
|
||||
units = units.split("x")
|
||||
if units.size == 2
|
||||
unit_quantity = units.first
|
||||
unit = units.last
|
||||
else
|
||||
unit_quantity = 1
|
||||
unit = units.first
|
||||
end
|
||||
|
||||
article = {
|
||||
:number => row[1],
|
||||
:name => name,
|
||||
:origin => origin,
|
||||
:manufacturer => manufacturer,
|
||||
:unit_quantity => unit_quantity,
|
||||
:unit => unit,
|
||||
:price => price_low, # Inklusive Rabattstufe von 10%
|
||||
:tax => 0.0 # Tax is included
|
||||
}
|
||||
|
||||
# test, if neccecary attributes exists
|
||||
if article[:unit].nil? || article[:price].nil? || article[:unit_quantity].nil?
|
||||
raise "Fehler: Einheit, Preis und MwSt. müssen gegeben sein: #{article.inspect}"
|
||||
end
|
||||
|
||||
yield article, nil, i
|
||||
yield nil, nil, i
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
|
@ -25,10 +25,14 @@ module FoodsoftArticleImport::Foodsoft
|
|||
# skip first header row
|
||||
if header_row
|
||||
header_row = false
|
||||
yield nil, nil, i
|
||||
next
|
||||
end
|
||||
# skip empty lines
|
||||
next if row[2].blank?
|
||||
if row[2].blank?
|
||||
yield nil, nil, i
|
||||
next
|
||||
end
|
||||
|
||||
article = {:number => row[1],
|
||||
:name => row[2],
|
||||
|
|
Loading…
Add table
Reference in a new issue