2014-03-06 16:26:16 +01:00
|
|
|
require 'csv'
|
|
|
|
|
2014-05-08 12:42:50 +02:00
|
|
|
class OrderCsv < RenderCSV
|
|
|
|
def header
|
|
|
|
[
|
|
|
|
OrderArticle.human_attribute_name(:units_to_order),
|
|
|
|
Article.human_attribute_name(:order_number),
|
|
|
|
Article.human_attribute_name(:name),
|
|
|
|
Article.human_attribute_name(:unit),
|
2014-09-03 17:36:48 +02:00
|
|
|
Article.human_attribute_name(:unit_quantity_short),
|
2014-05-08 12:42:50 +02:00
|
|
|
ArticlePrice.human_attribute_name(:price),
|
|
|
|
OrderArticle.human_attribute_name(:total_price)
|
|
|
|
]
|
2014-03-06 16:26:16 +01:00
|
|
|
end
|
|
|
|
|
2014-05-08 12:42:50 +02:00
|
|
|
def data
|
|
|
|
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
|
|
|
|
yield [
|
2021-03-01 15:27:26 +01:00
|
|
|
oa.units_to_order,
|
|
|
|
oa.article.order_number,
|
|
|
|
oa.article.name,
|
|
|
|
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)
|
|
|
|
]
|
2014-03-06 16:26:16 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|