diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb index 81e9383727..9e795fcc9d 100644 --- a/app/models/concerns/variant_stock.rb +++ b/app/models/concerns/variant_stock.rb @@ -106,10 +106,10 @@ module VariantStock # # This enables us to override this behaviour for variant overrides def move(quantity, originator = nil) - raise_error_if_no_stock_item_available + # Don't change variant stock if variant is on_demand or has been deleted + return if on_demand || deleted_at - # Don't change variant stock if variant is on_demand - return if on_demand + raise_error_if_no_stock_item_available # Creates a stock movement: it updates stock_item.count_on_hand and fills backorders # diff --git a/spec/models/spree/order_spec.rb b/spec/models/spree/order_spec.rb index 0d485041f9..e09e663396 100644 --- a/spec/models/spree/order_spec.rb +++ b/spec/models/spree/order_spec.rb @@ -283,6 +283,13 @@ describe Spree::Order do order.completed_at = Time.zone.now expect(order.can_cancel?).to be_truthy end + + it "should cancel order if product is soft deleted" do + o = FactoryBot.create(:completed_order_with_totals) + o.line_items.first.variant.product.tap(&:destroy) + o.cancel! + expect(Spree::Order.by_state(:canceled)).to include o + end end context "insufficient_stock_lines" do