foodsoft/lib/order_csv.rb

28 lines
862 B
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

require 'csv'
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),
ArticlePrice.human_attribute_name(:price),
OrderArticle.human_attribute_name(:total_price)
]
end
def data
@object.order_articles.ordered.includes([:article, :article_price]).all.map do |oa|
yield [
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.price * oa.article_price.unit_quantity),
number_to_currency(oa.total_price)
]
end
end
end