diff --git a/app/models/concerns/variant_stock.rb b/app/models/concerns/variant_stock.rb index 8eac3eb32e..0c7f535be5 100644 --- a/app/models/concerns/variant_stock.rb +++ b/app/models/concerns/variant_stock.rb @@ -100,13 +100,13 @@ module VariantStock # Here we depend only on variant.total_on_hand and variant.on_demand. # This way, variant_overrides only need to override variant.total_on_hand and variant.on_demand. def fill_status(quantity) - if on_hand >= quantity - on_hand = quantity - backordered = 0 - else - on_hand = [0, total_on_hand].max - backordered = on_demand ? (quantity - on_hand) : 0 - end + on_hand = if total_on_hand >= quantity || on_demand + quantity + else + [0, total_on_hand].max + end + + backordered = 0 [on_hand, backordered] end diff --git a/spec/models/spree/line_item_spec.rb b/spec/models/spree/line_item_spec.rb index 80d7b28b34..515ebdb8c6 100644 --- a/spec/models/spree/line_item_spec.rb +++ b/spec/models/spree/line_item_spec.rb @@ -155,9 +155,9 @@ module Spree order.shipment.update!(order) end - it "creates a shipment with backordered items" do + it "creates a shipment without backordered items" do expect(order.shipment.manifest.first.quantity).to eq 10 - expect(order.shipment.manifest.first.states).to eq 'on_hand' => 1, 'backordered' => 9 + expect(order.shipment.manifest.first.states).to eq 'on_hand' => 10 expect(order.shipment.manifest.first.variant).to eq line_item.variant end @@ -165,17 +165,17 @@ module Spree expect(variant_on_demand.reload.on_hand).to eq(-9) end - it "marks the inventory units as backorderd" do + it "does not mark inventory units as backorderd" do backordered_units = order.shipments.first.inventory_units.any?(&:backordered?) - expect(backordered_units).to be true + expect(backordered_units).to be false end - it "marks the shipment as backorderd" do - expect(order.shipments.first.backordered?).to be true + it "does not mark the shipment as backorderd" do + expect(order.shipments.first.backordered?).to be false end - it "does not allow the order to be shipped" do - expect(order.ready_to_ship?).to be false + it "allows the order to be shipped" do + expect(order.ready_to_ship?).to be true end end end