Skip to content

Commit

Permalink
Another fix for #28
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed Dec 26, 2023
1 parent 34c198f commit 6b8c112
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions app/helpers/articles_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def format_group_order_unit(article)
unit[:symbol] || unit[:name]
end

def format_supplier_order_unit_with_ratios(article)
base = format_supplier_article_unit(article)
return base if ArticleUnitsLib.unit_is_si_convertible(article.supplier_order_unit)

first_si_convertible_unit = article.article_unit_ratios.map(&:unit)
.find { |unit| ArticleUnitsLib.unit_is_si_convertible(unit) }
return base if first_si_convertible_unit.nil?

quantity = article.convert_quantity(1, article.supplier_order_unit, first_si_convertible_unit)
"#{base} (#{format_number(quantity)}#{ArticleUnitsLib.units.to_h[first_si_convertible_unit][:symbol]})"
end

def format_group_order_unit_with_ratios(article)
base = format_group_order_unit(article)
return base if ArticleUnitsLib.unit_is_si_convertible(article.group_order_unit)
Expand Down
2 changes: 1 addition & 1 deletion app/views/group_orders/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
.pull-left
#{heading_helper Article, :manufacturer}: #{order_article.article_version.manufacturer}
%br/
#{heading_helper Article, :units}: #{@order.stockit? ? order_article.article_version.article.quantity_available : @ordering_data[:order_articles][order_article.id][:unit]} * #{format_group_order_unit(order_article.article_version)}
#{heading_helper Article, :units}: #{@order.stockit? ? order_article.article_version.article.quantity_available : format_supplier_order_unit_with_ratios(order_article.article_version)}
%br/
#{heading_helper Article, :note}: #{order_article.article_version.note}
%br/
Expand Down

0 comments on commit 6b8c112

Please sign in to comment.