From 6803e0a8f9178e0b3499bc40f403b6f44d9a99e7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Tue, 16 May 2023 14:11:19 +1000 Subject: [PATCH] Fix error on summarising total_units --- .../orders_and_fulfillment/order_cycle_supplier_totals.rb | 8 +++++++- .../orders_cycle_supplier_totals_report_spec.rb | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb index fef10bca3c..447c2239ed 100644 --- a/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb +++ b/lib/reporting/reports/orders_and_fulfillment/order_cycle_supplier_totals.rb @@ -25,9 +25,15 @@ module Reporting group_by: :producer, header: true, summary_row: proc do |_key, _items, rows| + total_units = rows.map(&:total_units) + summary_total_units = if total_units.all?(&:present?) + rows.sum(&:total_units) + else + " " + end { quantity: rows.sum(&:quantity), - total_units: rows.sum(&:total_units), + total_units: summary_total_units, total_cost: rows.sum(&:total_cost) } end diff --git a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb index 15e2eb6da0..ebf1d44aae 100644 --- a/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb +++ b/spec/lib/reports/orders_and_fulfillment/orders_cycle_supplier_totals_report_spec.rb @@ -82,7 +82,7 @@ describe Reporting::Reports::OrdersAndFulfillment::OrderCycleSupplierTotals do expect(report_table[2][4]).to eq 0.601 # summary end - pending "is blank in summary when one line item misses a unit and another not" do + it "is blank in summary when one line item misses a unit and another not" do expect(report).to receive(:display_summary_row?).and_return(true) # This is not possible with the current code but was possible years ago.