diff --git a/app/jobs/subscription_placement_job.rb b/app/jobs/subscription_placement_job.rb index ee4369c1d9..4cd02392a4 100644 --- a/app/jobs/subscription_placement_job.rb +++ b/app/jobs/subscription_placement_job.rb @@ -62,6 +62,12 @@ class SubscriptionPlacementJob < ActiveJob::Base unavailable_stock_lines_for(order).each do |line_item| changes[line_item.id] = changes[line_item.id] || line_item.quantity line_item.update(quantity: 0) + + Spree::OrderInventory.new(order).verify(line_item, order.shipment) + end + if changes.present? + order.line_items.reload + order.update_order_fees! end changes end diff --git a/app/models/spree/order_inventory.rb b/app/models/spree/order_inventory.rb index 8416bb4755..44ff226609 100644 --- a/app/models/spree/order_inventory.rb +++ b/app/models/spree/order_inventory.rb @@ -98,8 +98,7 @@ module Spree inventory_unit.destroy removed_quantity += 1 end - - shipment.destroy if shipment.inventory_units.count == 0 + shipment.destroy if shipment.inventory_units.reload.count == 0 # removing this from shipment, and adding to stock_location if order.completed? diff --git a/spec/jobs/subscription_placement_job_spec.rb b/spec/jobs/subscription_placement_job_spec.rb index 32a621c436..96e79012a7 100644 --- a/spec/jobs/subscription_placement_job_spec.rb +++ b/spec/jobs/subscription_placement_job_spec.rb @@ -115,6 +115,18 @@ describe SubscriptionPlacementJob do expect(changes[line_item2.id]).to be 3 expect(changes[line_item3.id]).to be 3 end + + context "and the order has been placed" do + before do + allow(order).to receive(:ensure_available_shipping_rates) { true } + allow(order).to receive(:process_each_payment) { true } + job.send(:place_order, order.reload) + end + + it "removes the unavailable items from the shipment" do + expect(order.shipment.manifest.size).to eq 1 + end + end end end end