Skip to content

Commit

Permalink
On #64: Add missing unit labels
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Jul 26, 2024
1 parent 222ada6 commit 97a3f48
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
3 changes: 1 addition & 2 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 6 additions & 5 deletions app/helpers/orders_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,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
Expand Down
5 changes: 5 additions & 0 deletions lib/article_units_lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?

Expand Down

0 comments on commit 97a3f48

Please sign in to comment.