Merge pull request #7048 from andrewpbrett/fix-sub-manifests

Verify line item when placing sub order (Fix #6680)
This commit is contained in:
Andy Brett
2021-03-22 10:24:20 -07:00
committed by GitHub
3 changed files with 19 additions and 2 deletions

View File

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

View File

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

View File

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