gehirnpups

This commit is contained in:
viehlieb 2023-01-20 14:09:47 +01:00
parent 6655ad9900
commit 0ca60f53a6

View file

@ -35,59 +35,56 @@ module FoodsoftArticleImport
# check if the line is empty
next if 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?
next if matched.nil?
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
# 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
# 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
# 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