From f1c4f80be439a609d2397f66d60c7586765a4294 Mon Sep 17 00:00:00 2001 From: GeorgeThoppil Date: Sun, 23 Jan 2022 13:45:54 -0500 Subject: [PATCH] Adding deleted_at check on variant_stock move --- app/models/concerns/variant_stock.rb | 6 +++--- spec/models/spree/order_spec.rb | 7 +++++++ 2 files changed, 10 insertions(+), 3 deletions(-) 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