Adding deleted_at check on variant_stock move

This commit is contained in:
GeorgeThoppil
2022-01-23 13:45:54 -05:00
parent a6408007db
commit f1c4f80be4
2 changed files with 10 additions and 3 deletions

View File

@@ -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
#

View File

@@ -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