Compare commits
2 commits
971b9d7031
...
b31848744f
Author | SHA1 | Date | |
---|---|---|---|
b31848744f | |||
573851e549 |
4 changed files with 8 additions and 20 deletions
|
@ -35,16 +35,15 @@ module FoodsoftArticleImport
|
||||||
# @param file [File, Tempfile]
|
# @param file [File, Tempfile]
|
||||||
# @option opts [String] type file format (required) (see {.file_formats})
|
# @option opts [String] type file format (required) (see {.file_formats})
|
||||||
# @return [File, Roo::Spreadsheet] file with encoding set if needed
|
# @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
|
custom_file_path ||= nil
|
||||||
type ||= 'bnn'
|
type ||= 'bnn'
|
||||||
|
|
||||||
parser = file_formats[type]
|
parser = file_formats[type]
|
||||||
if block_given?
|
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
|
else
|
||||||
data = []
|
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
|
data
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -28,9 +28,9 @@ module FoodsoftArticleImport
|
||||||
RES_PARSE_UNIT_LIST.map { |r| /#{r}\s*$/ } +
|
RES_PARSE_UNIT_LIST.map { |r| /#{r}\s*$/ } +
|
||||||
RES_PARSE_UNIT_LIST.map { |r| /-#{r}/ }
|
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
|
custom_file_path ||= nil
|
||||||
opts = OPTIONS.merge(opts)
|
opts = OPTIONS.dup
|
||||||
opts[:liberal_parsing] = true
|
opts[:liberal_parsing] = true
|
||||||
opts[:col_sep] = ','
|
opts[:col_sep] = ','
|
||||||
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)
|
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)
|
||||||
|
|
|
@ -71,22 +71,11 @@ module FoodsoftArticleImport
|
||||||
# TODO: Complete deposit list....
|
# TODO: Complete deposit list....
|
||||||
article.merge!(deposit: translate(:deposit, row[26])) if translate(:deposit, row[26])
|
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?
|
if !row[62].nil?
|
||||||
# consider special prices
|
# consider special prices
|
||||||
article[:note] = "Sonderpreis: #{article[:price]} von #{row[62]} bis #{row[63]}"
|
article[:note] = "Sonderpreis: #{article[:price]} von #{row[62]} bis #{row[63]}"
|
||||||
yield article, :special, i
|
yield article, :special, i
|
||||||
|
|
||||||
# Check now for article status, we only consider outlisted articles right now
|
# Check now for article status, we only consider outlisted articles right now
|
||||||
# N=neu, A=Änderung, X=ausgelistet, R=Restbestand,
|
# N=neu, A=Änderung, X=ausgelistet, R=Restbestand,
|
||||||
# V=vorübergehend ausgelistet, W=wiedergelistet
|
# V=vorübergehend ausgelistet, W=wiedergelistet
|
||||||
|
|
|
@ -17,9 +17,9 @@ module FoodsoftArticleImport
|
||||||
|
|
||||||
# Parses Foodsoft file
|
# Parses Foodsoft file
|
||||||
# the yielded article is a simple hash
|
# 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
|
custom_file_path ||= nil
|
||||||
opts = OPTIONS.merge(opts)
|
opts = OPTIONS.dup
|
||||||
|
|
||||||
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)
|
ss = FoodsoftArticleImport.open_spreadsheet(file, **opts)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue