mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Adjust logic and specs
This commit is contained in:
@@ -63,6 +63,6 @@ module ReportsHelper
|
||||
end
|
||||
|
||||
def prices_sum(prices_list)
|
||||
prices_list.sum
|
||||
prices_list.compact.sum
|
||||
end
|
||||
end
|
||||
|
||||
@@ -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)) }
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user