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
|
# (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?
|
if row[:number].blank? && row[:unit_price].blank?
|
||||||
category = row[:name]
|
category = row[:name]
|
||||||
|
yield nil, nil, linenum
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
# skip products without a number
|
# skip products without a number
|
||||||
row[:number].blank? and next
|
if row[:number].blank?
|
||||||
|
yield nil, nil, linenum
|
||||||
|
next
|
||||||
|
end
|
||||||
# extract name and unit
|
# extract name and unit
|
||||||
errors = []
|
errors = []
|
||||||
notes = []
|
notes = []
|
||||||
|
@ -67,7 +71,10 @@ module FoodsoftArticleImport
|
||||||
manufacturer = nil
|
manufacturer = nil
|
||||||
prod_category = nil
|
prod_category = nil
|
||||||
RES_PARSE_UNIT.each do |re|
|
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])
|
unit = self.normalize_unit(m[3])
|
||||||
name = name.sub(re, '').sub(/\(\s*\)\s*$/,'').sub(/\s+/, ' ').sub(/\.\s*$/, '').strip
|
name = name.sub(re, '').sub(/\(\s*\)\s*$/,'').sub(/\s+/, ' ').sub(/\.\s*$/, '').strip
|
||||||
break
|
break
|
||||||
|
|
|
@ -33,58 +33,64 @@ module FoodsoftArticleImport
|
||||||
end
|
end
|
||||||
|
|
||||||
# check if the line is empty
|
# check if the line is empty
|
||||||
next if row[1].blank? || row[1] == "-"
|
unless row[1].blank? || row[1] == "-"
|
||||||
|
|
||||||
# Split string and remove beginning "
|
# Split string and remove beginning "
|
||||||
matched = row[2].gsub(/^\"/, "").gsub(/\"$/, "").match(REGEX[:main])
|
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
|
# Manufacturer
|
||||||
matched_name = name.match(REGEX[:origin])
|
if name.match(/^[A-Za-z]{2,3}\s{1}/)
|
||||||
if matched_name
|
name.gsub!(/^[A-Za-z]{2,3}\s{1}/, "")
|
||||||
name, origin = matched_name.captures
|
manufacturer = global_manufacturer
|
||||||
else
|
end
|
||||||
name, origin = name.gsub(/\s{2,}/, ""), nil
|
|
||||||
|
|
||||||
|
# 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
|
end
|
||||||
|
yield nil, nil, i
|
||||||
# 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
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -25,10 +25,14 @@ module FoodsoftArticleImport::Foodsoft
|
||||||
# skip first header row
|
# skip first header row
|
||||||
if header_row
|
if header_row
|
||||||
header_row = false
|
header_row = false
|
||||||
|
yield nil, nil, i
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
# skip empty lines
|
# skip empty lines
|
||||||
next if row[2].blank?
|
if row[2].blank?
|
||||||
|
yield nil, nil, i
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
article = {:number => row[1],
|
article = {:number => row[1],
|
||||||
:name => row[2],
|
:name => row[2],
|
||||||
|
|
Loading…
Add table
Reference in a new issue