From 5aef8e445e0414fc0c9c3d9e23d000bc830626c9 Mon Sep 17 00:00:00 2001 From: wvengen Date: Fri, 31 Jan 2014 13:07:13 +0100 Subject: [PATCH] add html units history line --- app/helpers/orders_helper.rb | 16 ++++++++++++---- app/views/orders/_articles.html.haml | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index cb4aebba..43b24068 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -18,13 +18,21 @@ module OrdersHelper options_for_select(options) end - def units_history_line(order_article) + # "1 ordered units, 2 billed, 2 received" + def units_history_line(order_article, options={}) if order_article.order.open? nil else - units_info = "#{order_article.units_to_order} #{OrderArticle.human_attribute_name :units_to_order, count: order_article.units_to_order}" - units_info += ", #{order_article.units_billed} #{OrderArticle.human_attribute_name :units_billed_short, count: order_article.units_billed}" unless order_article.units_billed.nil? - units_info += ", #{order_article.units_received} #{OrderArticle.human_attribute_name :units_received_short, count: order_article.units_received}" unless order_article.units_received.nil? + units_info = '' + [:units_to_order, :units_billed, :units_received].map do |unit| + if n = order_article.send(unit) + i18nkey = if units_info.blank? and options[:plain] then unit else "#{unit}_short" end + units_info += n.to_s + ' ' + units_info += pkg_helper(order_article.price) + ' ' unless options[:plain] or n == 0 + units_info += OrderArticle.human_attribute_name(i18nkey, count: n) + end + end + units_info.html_safe end end diff --git a/app/views/orders/_articles.html.haml b/app/views/orders/_articles.html.haml index 71806870..141d8a14 100644 --- a/app/views/orders/_articles.html.haml +++ b/app/views/orders/_articles.html.haml @@ -36,7 +36,7 @@ %td= "#{order_article.quantity} + #{order_article.tolerance}" - else %td= "#{order_article.quantity}" - %td{title: units_history_line(order_article)} + %td{title: units_history_line(order_article, plain: true)} = units = pkg_helper order_article.price %p