diff --git a/plugins/article_import/lib/foodsoft_article_import.rb b/plugins/article_import/lib/foodsoft_article_import.rb index 4472cca5..5bd48dd8 100644 --- a/plugins/article_import/lib/foodsoft_article_import.rb +++ b/plugins/article_import/lib/foodsoft_article_import.rb @@ -7,7 +7,6 @@ require 'csv' require 'yaml' require 'active_support/core_ext/hash/keys' require_relative 'foodsoft_article_import/bnn' -require_relative 'foodsoft_article_import/utf8_encoder' require_relative 'foodsoft_article_import/odin' require_relative 'foodsoft_article_import/foodsoft' module FoodsoftArticleImport diff --git a/plugins/article_import/lib/foodsoft_article_import/bnn.rb b/plugins/article_import/lib/foodsoft_article_import/bnn.rb index b07b9e45..008b6029 100644 --- a/plugins/article_import/lib/foodsoft_article_import/bnn.rb +++ b/plugins/article_import/lib/foodsoft_article_import/bnn.rb @@ -56,9 +56,9 @@ module FoodsoftArticleImport # check if the line is empty unless row[0] == '' || row[0].nil? article = { - name: UTF8Encoder.clean(row[6]), + name: row[6], order_number: row[0], - note: UTF8Encoder.clean(row[7]), + note: row[7], manufacturer: translate(:manufacturer, row[10]), origin: row[12], article_category: translate(:category, row[16]), diff --git a/plugins/article_import/lib/foodsoft_article_import/order_bnn.rb b/plugins/article_import/lib/foodsoft_article_import/order_bnn.rb deleted file mode 100644 index 59e690c1..00000000 --- a/plugins/article_import/lib/foodsoft_article_import/order_bnn.rb +++ /dev/null @@ -1,42 +0,0 @@ -module FoodsoftArticleImport - class OrderBnn < RenderCsv - def initialize(object, options = {}) - super - @options[:col_sep] = "" - @options[:row_sep] = "\n" - @options[:encoding] = 'IBM850' - end - - def header - customer_id = "000001" - delivery_date = Time.zone.now.strftime("%y%m%d") - pickup = " " - - ["D##{customer_id}#{delivery_date}#{pickup}#{@object.id}"] - end - - def data - @object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa| - yield [ - pad_to_length(oa.article.order_number, 13), - "+", - pad_float_values(oa.units_to_order), - pad_to_length(oa.article.name, 30), - pad_float_values(oa.article.unit_quantity), - pad_to_length(oa.article.unit, 14), - pad_to_length(oa.article.manufacturer, 3), - pad_to_length("", 26) - ] - end - end - - def pad_float_values(number, digits_before=4, digits_after=3) - format_string = "%0#{digits_before + digits_after}d" - formatted_number = sprintf(format_string, (number * 10 ** digits_after).to_i) - end - - def pad_to_length(string, length) - string.to_s.rjust(length, " ")[0, length] - end - end -end \ No newline at end of file diff --git a/plugins/article_import/lib/foodsoft_article_import/utf8_encoder.rb b/plugins/article_import/lib/foodsoft_article_import/utf8_encoder.rb deleted file mode 100644 index 1edb6727..00000000 --- a/plugins/article_import/lib/foodsoft_article_import/utf8_encoder.rb +++ /dev/null @@ -1,11 +0,0 @@ -# frozen_string_literal: true - -module UTF8Encoder - def self.clean(string) - if string.nil? - string - else - string.encode('UTF-8') - end - end -end diff --git a/plugins/article_import/spec/lib/foodsoft/foodsoft_article_import_foodsoft_spec.rb b/plugins/article_import/spec/lib/foodsoft/foodsoft_article_import_foodsoft_spec.rb index 12ad16d7..ce78b12b 100644 --- a/plugins/article_import/spec/lib/foodsoft/foodsoft_article_import_foodsoft_spec.rb +++ b/plugins/article_import/spec/lib/foodsoft/foodsoft_article_import_foodsoft_spec.rb @@ -6,14 +6,6 @@ require 'foodsoft_article_import' describe FoodsoftArticleImport do files_path = File.expand_path '../../files', __dir__ foodsoft_files_path = File.join(files_path, 'foodsoft') - puts " - " + "______________" + " - " + "______________" + " - " + "______________" + " - " + "#{foodsoft_files_path}" + " - " + "______________"+ " - " + "______________"+ " - " + "______________" dummy_article = { order_number: '1', name: 'product', note: 'bio', manufacturer: 'someone', origin: 'eu', unit: '1 kg', price: '1.23', tax: '6', unit_quantity: '10', article_category: 'coolstuff', deposit: '0' }