Fix adjustment calculations; only "eligible" adjustments should be regarded as applied to an order.

When an order is submitted and the payment fails, the failed payment's adjustments (payment fees) are set to `eligible: false` to indicate they do not apply. These should not be counted as being included in an order's adjustments.
This commit is contained in:
Matt-Yorkley
2020-08-19 12:52:40 +01:00
parent 977ab26b00
commit 3badaa07d2
2 changed files with 4 additions and 4 deletions

View File

@@ -57,11 +57,12 @@ class OrderAdjustmentsFetcher
if adjustments_eager_loaded?
adjustment_scope = public_send("#{scope}_scope")
# Adjustments are already loaded here, this block is using `Array#select`
adjustments.select do |adjustment|
match_by_scope(adjustment, adjustment_scope)
match_by_scope(adjustment, adjustment_scope) && match_by_scope(adjustment, eligible_scope)
end
else
adjustments.where(nil).public_send scope
adjustments.where(nil).eligible.public_send scope
end
end

View File

@@ -95,8 +95,7 @@ RSpec.describe OpenFoodNetwork::OrdersAndFulfillmentsReport::CustomerTotalsRepor
failed_payment.adjustment.update amount: 456.00, eligible: false, state: "finalized"
end
xit "shows the correct payment fee amount for the order" do
# Fails; the sum of adjustments for both failed and complete payments is shown
it "shows the correct payment fee amount for the order" do
payment_fee_field = report_table.last[12]
expect(payment_fee_field).to eq completed_payment.adjustment.amount
end