Skip to content

Commit

Permalink
Include Refund Total in Outstanding Balance calculation
Browse files Browse the repository at this point in the history
Based on the regression test added in solidusio#1926 this change fixes
that spec by including refund_total in outstanding_balance
calculation if the order has not been canceled.
  • Loading branch information
ericsaupe committed Jun 5, 2017
1 parent fa8d6af commit a198895
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ def outstanding_balance
if state == 'canceled'
-1 * payment_total
else
total - payment_total
total - payment_total - refund_total
end
end

Expand Down
6 changes: 3 additions & 3 deletions core/spec/models/spree/order/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ module Spree

context "for non-canceled orders" do
it 'should incorporate refund reimbursements' do
# Order Total - Payment Total
# 110 - 100 = 10
expect(order.outstanding_balance).to eq 10
# Order Total - Payment Total - Refund Total
# 110 - 100 - 10 = 0
expect(order.outstanding_balance).to eq 0
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
expect(order.outstanding_balance).to be_negative
expect(order.payment_state).to eq('credit_owed')
create(:refund, amount: order.outstanding_balance.abs, payment: payment, transaction_id: nil)
order.reload
order.update!
expect(order.outstanding_balance).to eq(0)
expect(order.payment_state).to eq('paid')
end
Expand Down

0 comments on commit a198895

Please sign in to comment.