remove utf-8 encoder

This commit is contained in:
viehlieb 2023-03-30 10:18:09 +02:00
parent 5c315d98ea
commit d114a82125
5 changed files with 2 additions and 64 deletions

View file

@ -7,7 +7,6 @@ require 'csv'
require 'yaml' require 'yaml'
require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/keys'
require_relative 'foodsoft_article_import/bnn' require_relative 'foodsoft_article_import/bnn'
require_relative 'foodsoft_article_import/utf8_encoder'
require_relative 'foodsoft_article_import/odin' require_relative 'foodsoft_article_import/odin'
require_relative 'foodsoft_article_import/foodsoft' require_relative 'foodsoft_article_import/foodsoft'
module FoodsoftArticleImport module FoodsoftArticleImport

View file

@ -56,9 +56,9 @@ module FoodsoftArticleImport
# check if the line is empty # check if the line is empty
unless row[0] == '' || row[0].nil? unless row[0] == '' || row[0].nil?
article = { article = {
name: UTF8Encoder.clean(row[6]), name: row[6],
order_number: row[0], order_number: row[0],
note: UTF8Encoder.clean(row[7]), note: row[7],
manufacturer: translate(:manufacturer, row[10]), manufacturer: translate(:manufacturer, row[10]),
origin: row[12], origin: row[12],
article_category: translate(:category, row[16]), article_category: translate(:category, row[16]),

View file

@ -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

View file

@ -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

View file

@ -6,14 +6,6 @@ require 'foodsoft_article_import'
describe FoodsoftArticleImport do describe FoodsoftArticleImport do
files_path = File.expand_path '../../files', __dir__ files_path = File.expand_path '../../files', __dir__
foodsoft_files_path = File.join(files_path, 'foodsoft') 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', 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' } unit: '1 kg', price: '1.23', tax: '6', unit_quantity: '10', article_category: 'coolstuff', deposit: '0' }