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 track quantity for line items (#13074)

brozekb642a5c7929e
diff --git a/core/app/models/spree/order_inventory.rb b/core/app/models/spree/order_inventory.rb
index e00db54ece..167fec77ca 100644
--- a/core/app/models/spree/order_inventory.rb
+++ b/core/app/models/spree/order_inventory.rb
@@ -84,7 +84,7 @@ module Spree
end
# adding to this shipment, and removing from stock_location
- if order.completed?
+ if order.completed? && variant.should_track_inventory?
shipment.stock_location.unstock(variant, quantity, shipment)
end
diff --git a/core/spec/models/spree/order_inventory_spec.rb b/core/spec/models/spree/order_inventory_spec.rb
index edac2956f1..c177a54b5d 100644
--- a/core/spec/models/spree/order_inventory_spec.rb
+++ b/core/spec/models/spree/order_inventory_spec.rb
@@ -49,6 +49,8 @@ describe Spree::OrderInventory, type: :model do
it 'creates only on hand inventory units' do
variant.stock_items.destroy_all
+ expect_any_instance_of(Spree::StockLocation).not_to receive(:unstock)
+
# The before_save callback in LineItem would verify inventory
line_item = Spree::Cart::AddItem.call(order: order, variant: variant, options: { shipment: shipment }).value
@@ -66,6 +68,8 @@ describe Spree::OrderInventory, type: :model do
it 'creates only on hand inventory units' do
variant.stock_items.destroy_all
+ expect_any_instance_of(Spree::StockLocation).not_to receive(:unstock)
+
line_item = Spree::Cart::AddItem.call(order: order, variant: variant).value
subject.verify(shipment)