Skip to content

Commit

Permalink
Should create all inventory_units as sold when :track_inventory_level…
Browse files Browse the repository at this point in the history
…s is false.

[spree#1749 state:resolved]
  • Loading branch information
BDQ committed Nov 11, 2010
1 parent 1b6bd55 commit 4d4f410
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions core/app/models/inventory_unit.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ def self.assign_opening_inventory(order)
# #
def self.increase(order, variant, quantity) def self.increase(order, variant, quantity)
# calculate number of sold vs. backordered units # calculate number of sold vs. backordered units
if variant.count_on_hand == 0 if variant.on_hand == 0
back_order = quantity back_order = quantity
sold = 0 sold = 0
elsif variant.count_on_hand < quantity elsif variant.on_hand.present? and variant.on_hand < quantity
back_order = quantity - (variant.count_on_hand < 0 ? 0 : variant.count_on_hand) back_order = quantity - (variant.on_hand < 0 ? 0 : variant.on_hand)
sold = quantity - back_order sold = quantity - back_order
else else
back_order = 0 back_order = 0
Expand Down
17 changes: 13 additions & 4 deletions core/spec/models/inventory_unit_spec.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper' require 'spec_helper'


describe InventoryUnit do describe InventoryUnit do
let(:variant) { mock_model(Variant, :count_on_hand => 95) } let(:variant) { mock_model(Variant, :on_hand => 95) }
let(:line_item) { mock_model(LineItem, :variant => variant, :quantity => 5) } let(:line_item) { mock_model(LineItem, :variant => variant, :quantity => 5) }
let(:order) { mock_model(Order, :line_items => [line_item], :inventory_units => [], :shipments => mock('shipments'), :completed? => true) } let(:order) { mock_model(Order, :line_items => [line_item], :inventory_units => [], :shipments => mock('shipments'), :completed? => true) }


Expand Down Expand Up @@ -51,6 +51,15 @@
InventoryUnit.increase(order, variant, 5) InventoryUnit.increase(order, variant, 5)
end end


context "and :create_inventory_units is true" do
before { Spree::Config.set :create_inventory_units => true }
let(:variant) { stub_model(Variant, :count_on_hand => 95) }

it "should create units as sold regardless of count_on_hand value " do
InventoryUnit.should_receive(:create_units).with(order, variant, 5, 0)
InventoryUnit.increase(order, variant, 5)
end
end
end end


context "when :create_inventory_units is true" do context "when :create_inventory_units is true" do
Expand All @@ -67,7 +76,7 @@
end end


context "and partial units are in stock" do context "and partial units are in stock" do
before { variant.stub(:count_on_hand).and_return(2) } before { variant.stub(:on_hand).and_return(2) }


it "should create units as sold and backordered" do it "should create units as sold and backordered" do
InventoryUnit.should_receive(:create_units).with(order, variant, 2, 3) InventoryUnit.should_receive(:create_units).with(order, variant, 2, 3)
Expand All @@ -76,7 +85,7 @@
end end


context "and zero units are in stock" do context "and zero units are in stock" do
before { variant.stub(:count_on_hand).and_return(0) } before { variant.stub(:on_hand).and_return(0) }


it "should create units as backordered" do it "should create units as backordered" do
InventoryUnit.should_receive(:create_units).with(order, variant, 0, 5) InventoryUnit.should_receive(:create_units).with(order, variant, 0, 5)
Expand All @@ -85,7 +94,7 @@
end end


context "and less than zero units are in stock" do context "and less than zero units are in stock" do
before { variant.stub(:count_on_hand).and_return(-9) } before { variant.stub(:on_hand).and_return(-9) }


it "should create units as backordered" do it "should create units as backordered" do
InventoryUnit.should_receive(:create_units).with(order, variant, 0, 5) InventoryUnit.should_receive(:create_units).with(order, variant, 0, 5)
Expand Down

0 comments on commit 4d4f410

Please sign in to comment.