diff --git a/app/helpers/articles_helper.rb b/app/helpers/articles_helper.rb index 5066d3a8..b9de5b1d 100644 --- a/app/helpers/articles_helper.rb +++ b/app/helpers/articles_helper.rb @@ -19,8 +19,7 @@ def format_unit(unit_property, article) unit_code = article.send(unit_property) return article.unit if unit_code.nil? - unit = ArticleUnitsLib.units.to_h[unit_code] - unit[:symbol] || unit[:name] + ArticleUnitsLib.human_readable_unit(unit_code) end def format_supplier_order_unit(article) diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb index 46a47728..24c1d3c5 100644 --- a/app/helpers/orders_helper.rb +++ b/app/helpers/orders_helper.rb @@ -77,15 +77,16 @@ def ordered_quantities_different_from_group_orders?(order_article, ordered_mark # Sensible in tables with multiple columns. # @return [String] Text showing unit and unit quantity when applicable. def pkg_helper(article, options = {}) - if options[:unit].nil? || article.supplier_order_unit == options[:unit] + unit_code = options[:unit] || article.supplier_order_unit + if unit_code == article.supplier_order_unit first_ratio = article&.article_unit_ratios&.first - return '' if first_ratio.nil? || first_ratio.quantity == 1 + return ArticleUnitsLib.human_readable_unit(unit_code) if first_ratio.nil? || first_ratio.quantity == 1 - uq_text = "× #{number_with_precision(first_ratio.quantity, precision: 3, strip_insignificant_zeros: true)} #{ArticleUnitsLib.units[first_ratio.unit][:symbol]}" + uq_text = "× #{number_with_precision(first_ratio.quantity, precision: 3, strip_insignificant_zeros: true)} #{ArticleUnitsLib.human_readable_unit(first_ratio.unit)}" else - unit = ArticleUnitsLib.units[options[:unit]] - uq_text = unit[:symbol] || unit[:name] + uq_text = ArticleUnitsLib.human_readable_unit(unit_code) end + uq_text = content_tag(:span, uq_text, class: 'hidden-phone') if options[:soft_uq] if options[:plain] uq_text diff --git a/lib/article_units_lib.rb b/lib/article_units_lib.rb index 7824833e..481a74b1 100644 --- a/lib/article_units_lib.rb +++ b/lib/article_units_lib.rb @@ -69,6 +69,11 @@ def self.unit_is_si_convertible(code) !units.to_h[code]&.dig(:conversionFactor).nil? end + def self.human_readable_unit(unit_code) + unit = units.to_h[unit_code] + unit[:symbol] || unit[:name] + end + def self.get_translated_name_for_code(code, default_nil: false) return nil if code.blank?