mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-25 05:45:15 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user