Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Fix: Refunded orders no longer show as paid

Łukasz Adamczyk357e38d17e5a
diff --git a/spree/core/app/workflows/spree/carts/recalculate_totals.rb b/spree/core/app/workflows/spree/carts/recalculate_totals.rb
index b8cd2aa47c..5d6ae750ef 100644
--- a/spree/core/app/workflows/spree/carts/recalculate_totals.rb
+++ b/spree/core/app/workflows/spree/carts/recalculate_totals.rb
@@ -166,8 +166,6 @@ module Spree
updated_at: Time.current
}
if cart.is_a?(Spree::Order)
- columns[:payment_status] = cart.payment_status
- columns[:fulfillment_status] = cart.fulfillment_status
columns[:commission_amount_total] = cart.commission_amount_total
columns[:commission_tax_total] = cart.commission_tax_total
columns[:commission_total] = cart.commission_total
diff --git a/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb b/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
index 3b42497e00..296d8b5023 100644
--- a/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
+++ b/spree/core/spec/workflows/spree/carts/recalculate_totals_spec.rb
@@ -28,6 +28,19 @@ module Spree
expect(order.reload.payment_total).to eq(payment.amount - 5)
end
+
+ it 'leaves the derived statuses alone, so a stale instance cannot undo them' do
+ order = create(:completed_order_with_totals, store: store)
+ Spree::Order.where(id: order.id).update_all(payment_status: 'refunded', fulfillment_status: 'fulfilled')
+ order.send(:write_attribute, :payment_status, 'paid')
+ order.send(:write_attribute, :fulfillment_status, 'pending')
+
+ described_class.call(cart: order)
+
+ order.reload
+ expect(order.payment_status).to eq('refunded')
+ expect(order.fulfillment_status).to eq('fulfilled')
+ end
end
describe 'the completed-order money freeze' do