Adjust logic and specs

This commit is contained in:
François Turbelin
2026-02-27 14:07:38 +01:00
parent de52e21ee9
commit 08691f81a1
4 changed files with 4 additions and 4 deletions

View File

@@ -63,6 +63,6 @@ module ReportsHelper
end
def prices_sum(prices_list)
prices_list.sum
prices_list.compact.sum
end
end

View File

@@ -11,7 +11,7 @@ module Reporting
product_total_price: proc { |orders| prices_sum(orders.map(&:item_total)) },
shipping_total_price: proc { |orders| prices_sum(orders.map(&:ship_total)) },
outstanding_balance_price: proc do |orders|
prices_sum(orders.map(&:outstanding_balance))
prices_sum(orders.map(&:outstanding_balance).map(&:amount))
end,
total_price: proc { |orders| prices_sum(orders.map(&:total)) }
}

View File

@@ -14,7 +14,7 @@ module Reporting
eft_price: proc { |orders| total_by_payment_method(orders, "EFT") },
paypal_price: proc { |orders| total_by_payment_method(orders, "PayPal") },
outstanding_balance_price: proc { |orders|
prices_sum(orders.map(&:outstanding_balance))
prices_sum(orders.map(&:outstanding_balance).map(&:amount))
}
}
end

View File

@@ -24,7 +24,7 @@ RSpec.describe ReportsHelper do
describe "#prices_sum" do
it "sums to prices list roundind to 2 decimals" do
expect(helper.prices_sum([1, nil, 2.333333, 1.5, 2.0])).to eq(6.83)
expect(helper.prices_sum([1, nil, 2.33, 1.5, 2.0])).to eq(6.83)
end
end
end