Compare commits

...

2 commits

Author SHA1 Message Date
b31848744f remove options from parsemethod 2023-02-26 13:23:09 +01:00
573851e549 add to_s.gsub4 2023-02-20 23:49:59 +01:00
4 changed files with 8 additions and 20 deletions

View file

@ -35,16 +35,15 @@ 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, **opts, &blk)
def self.parse(file, custom_file_path: nil, type: nil, &blk)
custom_file_path ||= nil
type ||= 'bnn'
parser = file_formats[type]
if block_given?
parser.parse(file, custom_file_path: custom_file_path, **opts, &blk)
parser.parse(file, custom_file_path: custom_file_path, &blk)
else
data = []
parser.parse(file, custom_file_path: custom_file_path, **opts) { |a| data << a }
parser.parse(file, custom_file_path: custom_file_path) { |a| data << a }
data
end
end

View file

@ -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, **opts)
def self.parse(file, custom_file_path: nil)
custom_file_path ||= nil
opts = OPTIONS.merge(opts)
opts = OPTIONS.dup
opts[:liberal_parsing] = true
opts[:col_sep] = ','
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)

View file

@ -71,22 +71,11 @@ 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

View file

@ -17,9 +17,9 @@ module FoodsoftArticleImport
# Parses Foodsoft file
# the yielded article is a simple hash
def self.parse(file, custom_file_path: nil, **opts)
def self.parse(file, custom_file_path: nil)
custom_file_path ||= nil
opts = OPTIONS.merge(opts)
opts = OPTIONS.dup
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)