From 3f3d7c4e3b3973b90d20e2d9c248eba20449a4ce Mon Sep 17 00:00:00 2001 From: wvengen Date: Wed, 3 Sep 2014 17:36:48 +0200 Subject: [PATCH] export + encoding fix (ruby 1.9.3) Conflicts: lib/order_csv.rb --- lib/order_csv.rb | 7 +++++-- lib/render_csv.rb | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/order_csv.rb b/lib/order_csv.rb index d2c458c2..4fe92a25 100644 --- a/lib/order_csv.rb +++ b/lib/order_csv.rb @@ -8,6 +8,7 @@ class OrderCsv < RenderCSV Article.human_attribute_name(:order_number), Article.human_attribute_name(:name), Article.human_attribute_name(:unit), + Article.human_attribute_name(:unit_quantity_short), ArticlePrice.human_attribute_name(:price), OrderArticle.human_attribute_name(:total_price) ] @@ -19,10 +20,12 @@ class OrderCsv < RenderCSV oa.units_to_order, oa.article.order_number, oa.article.name, - oa.article.unit + (oa.price.unit_quantity > 1 ? " × #{oa.price.unit_quantity}" : ''), - number_to_currency(oa.article.price * oa.article.unit_quantity), + oa.article.unit, + oa.price.unit_quantity > 1 ? oa.price.unit_quantity : nil, + number_to_currency(oa.price.price * oa.price.unit_quantity), number_to_currency(oa.total_price) ] end end + end diff --git a/lib/render_csv.rb b/lib/render_csv.rb index ad79612b..b643e4b4 100644 --- a/lib/render_csv.rb +++ b/lib/render_csv.rb @@ -36,8 +36,8 @@ class RenderCSV File.open("#{Rails.root}/tmp/#{self.class.to_s.underscore}.csv", 'w') {|f| f.write(to_csv.force_encoding(encoding)) } end - # XXX avoid encoding confusion when using unicode whitespace + # XXX disable unit to avoid encoding problems, both in unit and whitespace. Also allows computations in spreadsheet. def number_to_currency(number, options={}) - super(number, options).gsub("\u202f", ' ') + super(number, options.merge({unit: nil})) end end