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 splitting shipments (#12462)

Łukasz Adamczyk6c9181336333
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index a5181abe27..67f34971bf 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -45,6 +45,7 @@ module Spree
scope :pending, -> { with_state('pending') }
scope :ready, -> { with_state('ready') }
scope :shipped, -> { with_state('shipped') }
+ scope :ready_or_pending, -> { where(state: %w(ready pending)) }
scope :trackable, -> { where("tracking IS NOT NULL AND tracking != ''") }
scope :with_state, ->(*s) { where(state: s) }
# sort by most recent shipped_at, falling back to created_at. add "id desc" to make specs that involve this scope more deterministic.
diff --git a/core/spec/models/spree/shipment_spec.rb b/core/spec/models/spree/shipment_spec.rb
index 7283db5274..28bbaf7abc 100644
--- a/core/spec/models/spree/shipment_spec.rb
+++ b/core/spec/models/spree/shipment_spec.rb
@@ -890,4 +890,18 @@ describe Spree::Shipment, type: :model do
expect(state_change.next_state).to eq('ready')
end
end
+
+ describe '.ready_or_pending' do
+ subject { described_class.ready_or_pending }
+
+ let!(:ready_shipments) { create_list(:shipment, 2, state: 'ready') }
+ let!(:pending_shipments) { create_list(:shipment, 2, state: 'pending') }
+ let!(:shipped_shipments) { create_list(:shipment, 2, state: 'shipped') }
+
+ it 'returns shipments with state ready or pending' do
+ expect(subject.pluck(:state).uniq).to contain_exactly('ready', 'pending')
+ expect(subject).to include(*ready_shipments, *pending_shipments)
+ expect(subject).not_to include(*shipped_shipments)
+ end
+ end
end