diff --git a/lib/foodsoft_article_import.rb b/lib/foodsoft_article_import.rb index 22de3ee..289ecb7 100644 --- a/lib/foodsoft_article_import.rb +++ b/lib/foodsoft_article_import.rb @@ -35,15 +35,16 @@ module FoodsoftArticleImport # @param file [File, Tempfile] # @option opts [String] type file format (required) (see {.file_formats}) # @return [File, Roo::Spreadsheet] file with encoding set if needed - def self.parse(file, custom_file_path: nil, type: nil, &blk) + def self.parse(file, custom_file_path: nil, type: nil, **opts, &blk) custom_file_path ||= nil type ||= 'bnn' + parser = file_formats[type] if block_given? - parser.parse(file, custom_file_path: custom_file_path, &blk) + parser.parse(file, custom_file_path: custom_file_path, **opts, &blk) else data = [] - parser.parse(file, custom_file_path: custom_file_path) { |a| data << a } + parser.parse(file, custom_file_path: custom_file_path, **opts) { |a| data << a } data end end diff --git a/lib/foodsoft_article_import/bioromeo.rb b/lib/foodsoft_article_import/bioromeo.rb index 054439f..135cf1b 100644 --- a/lib/foodsoft_article_import/bioromeo.rb +++ b/lib/foodsoft_article_import/bioromeo.rb @@ -28,9 +28,9 @@ module FoodsoftArticleImport RES_PARSE_UNIT_LIST.map { |r| /#{r}\s*$/ } + RES_PARSE_UNIT_LIST.map { |r| /-#{r}/ } - def self.parse(file, custom_file_path: nil) + def self.parse(file, custom_file_path: nil, **opts) custom_file_path ||= nil - opts = OPTIONS.dup + opts = OPTIONS.merge(opts) opts[:liberal_parsing] = true opts[:col_sep] = ',' ss = FoodsoftArticleImport.open_spreadsheet(file, **opts) diff --git a/lib/foodsoft_article_import/bnn.rb b/lib/foodsoft_article_import/bnn.rb index 06c7b36..337a96e 100644 --- a/lib/foodsoft_article_import/bnn.rb +++ b/lib/foodsoft_article_import/bnn.rb @@ -71,11 +71,22 @@ module FoodsoftArticleImport # TODO: Complete deposit list.... article.merge!(deposit: translate(:deposit, row[26])) if translate(:deposit, row[26]) + # get scale prices if exists + # article.merge!(:scale_quantity => row[40], :scale_price => row[41]) unless row[40].nil? or row[41].nil? + unless row[37].nil? && row[65].nil? && row[66].nil? + scale_factor = row[66].gsub(',', '.').to_f + price = row[37].gsub(',', '.').to_f + price_per = (scale_factor * price).to_s.gsub('.', ',') + article.merge!(:price_per => price_per) + article.merge!(:unit_symbol => row[65] ) + end + + if !row[62].nil? # consider special prices article[:note] = "Sonderpreis: #{article[:price]} von #{row[62]} bis #{row[63]}" yield article, :special, i - + # Check now for article status, we only consider outlisted articles right now # N=neu, A=Änderung, X=ausgelistet, R=Restbestand, # V=vorübergehend ausgelistet, W=wiedergelistet diff --git a/lib/foodsoft_article_import/foodsoft.rb b/lib/foodsoft_article_import/foodsoft.rb index 25ff4ba..5fd09b4 100644 --- a/lib/foodsoft_article_import/foodsoft.rb +++ b/lib/foodsoft_article_import/foodsoft.rb @@ -17,9 +17,9 @@ module FoodsoftArticleImport # Parses Foodsoft file # the yielded article is a simple hash - def self.parse(file, custom_file_path: nil) + def self.parse(file, custom_file_path: nil, **opts) custom_file_path ||= nil - opts = OPTIONS.dup + opts = OPTIONS.merge(opts) ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)