diff --git a/lib/open_food_network/orders_and_fulfillments_report.rb b/lib/open_food_network/orders_and_fulfillments_report.rb index 01b2ae7617..fbac2f6551 100644 --- a/lib/open_food_network/orders_and_fulfillments_report.rb +++ b/lib/open_food_network/orders_and_fulfillments_report.rb @@ -45,6 +45,17 @@ module OpenFoodNetwork proc { |line_items| line_items.first.variant.product.name } end + def total_units(line_items) + return " " if not_all_have_unit?(line_items) + + total_units = line_items.sum do |li| + product = li.variant.product + li.quantity * li.unit_value / scale_factor(product) + end + + total_units.round(3) + end + private def report @@ -62,17 +73,6 @@ module OpenFoodNetwork end end - def total_units(line_items) - return " " if not_all_have_unit?(line_items) - - total_units = line_items.sum do |li| - product = li.variant.product - li.quantity * li.unit_value / scale_factor(product) - end - - total_units.round(3) - end - def not_all_have_unit?(line_items) line_items.map { |li| li.unit_value.nil? }.any? end