From 52b31dd302e35e685b75d6aba70bc1030762ea4a Mon Sep 17 00:00:00 2001
From: Florian Lentsch <office@florian-lentsch.at>
Date: Sun, 3 Nov 2024 10:31:25 +0100
Subject: [PATCH] Fixes error when displaying old units

---
 app/helpers/orders_helper.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/app/helpers/orders_helper.rb b/app/helpers/orders_helper.rb
index 54233d05..18889f40 100644
--- a/app/helpers/orders_helper.rb
+++ b/app/helpers/orders_helper.rb
@@ -80,7 +80,11 @@ def pkg_helper(article, options = {})
     unit_code = options[:unit] || article.supplier_order_unit
     if unit_code == article.supplier_order_unit
       first_ratio = article&.article_unit_ratios&.first
-      return ArticleUnitsLib.human_readable_unit(unit_code) if first_ratio.nil? || first_ratio.quantity == 1
+      if first_ratio.nil? || first_ratio.quantity == 1
+        return "x #{article.unit}" if unit_code.nil?
+
+        return ArticleUnitsLib.human_readable_unit(unit_code)
+      end
 
       uq_text = "× #{number_with_precision(first_ratio.quantity, precision: 3, strip_insignificant_zeros: true)} #{ArticleUnitsLib.human_readable_unit(first_ratio.unit)}"
     else