Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/app/models/spree/order_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def update_shipments
end

def recalculate_payment_total
order.payment_total = payments.completed.includes(:refunds).sum { |payment| payment.amount - payment.refunds.sum(:amount) }
order.payment_total = payments.completed.includes(:refunds).sum { |payment| payment.amount - payment.refunds.sum(&:amount) }
end
alias_method :update_payment_total, :recalculate_payment_total
deprecate update_payment_total: :recalculate_payment_total, deprecator: Spree.deprecator
Expand Down
11 changes: 11 additions & 0 deletions core/spec/models/spree/order_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ module Spree
end
end

context "recalculating payment totals" do
before { create(:payment_with_refund, order:, amount: 33.25, refund_amount: 3) }
Comment thread
tvdeyen marked this conversation as resolved.

it "sums refunds from a single preload, not once per payment" do
create(:payment_with_refund, order:, amount: 20, refund_amount: 2)
Comment thread
tvdeyen marked this conversation as resolved.
order.payments.reset

expect { updater.recalculate }.to make_database_queries(matching: /from .spree_refunds./i, count: 1)
end
end
Comment thread
tvdeyen marked this conversation as resolved.

it "update item total" do
expect {
updater.recalculate
Expand Down
Loading