Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Outstanding balance uses reimbursement
Christopher Hummel20e69d0e8a19
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rbindex d1aed12014..0a51e48a37 100644--- a/core/app/models/spree/order.rb+++ b/core/app/models/spree/order.rb@@ -297,15 +297,15 @@ module Spreedef outstanding_balanceif canceled?-1 * payment_total- elsif refunds.exists?- # If refund has happened add it back to total to prevent balance_due payment state- # See: https://github.com/spree/spree/issues/6229 & https://github.com/spree/spree/issues/8136- total - (payment_total + refunds.sum(:amount))else- total - payment_total+ total - (payment_total + reimbursement_paid_total)endend+ def reimbursement_paid_total+ reimbursements.sum(&:paid_amount)+ end+def outstanding_balance?outstanding_balance != 0enddiff --git a/core/spec/models/spree/order/payment_spec.rb b/core/spec/models/spree/order/payment_spec.rbindex e8d012f5c7..d00c2f6c8b 100644--- a/core/spec/models/spree/order/payment_spec.rb+++ b/core/spec/models/spree/order/payment_spec.rb@@ -178,11 +178,13 @@ module Spreeorder.total = 30.30expect(order.outstanding_balance).to eq(10.10)end+it 'returns negative amount when payment_total is greater than total' doorder.total = 8.20order.payment_total = 10.20expect(order.outstanding_balance).to be_within(0.001).of(-2.00)end+it 'incorporates refund reimbursements' do# Creates an order w/total 10reimbursement = create :reimbursement@@ -200,7 +202,7 @@ module Spreeexpect(order.outstanding_balance).to eq 0end- it 'incorporates refunds' do+ it 'does not incorporate refunds without a reimbursement' doorder = create(:completed_order_with_totals)calculator = order.shipments.first.shipping_method.calculator@@ -211,8 +213,9 @@ module Spreecreate(:refund, amount: 10, payment: order.payments.first)order.update_with_updater!-- expect(order.outstanding_balance).to eq 0+ # Order Total - (Payment Total + Reimbursed)+ # 10 - (0 + 0) = 0+ expect(order.outstanding_balance).to eq 10endend