Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Should create all inventory_units as sold when :track_inventory_level…

…s is false.

[#1749 state:resolved]
  • Loading branch information...
commit 4d4f41054bcf09fee4d2e7b6c690c4f9b7a0fbf1 1 parent 1b6bd55
@BDQ BDQ authored
View
6 core/app/models/inventory_unit.rb
@@ -48,11 +48,11 @@ def self.assign_opening_inventory(order)
#
def self.increase(order, variant, quantity)
# calculate number of sold vs. backordered units
- if variant.count_on_hand == 0
+ if variant.on_hand == 0
back_order = quantity
sold = 0
- elsif variant.count_on_hand < quantity
- back_order = quantity - (variant.count_on_hand < 0 ? 0 : variant.count_on_hand)
+ elsif variant.on_hand.present? and variant.on_hand < quantity
+ back_order = quantity - (variant.on_hand < 0 ? 0 : variant.on_hand)
sold = quantity - back_order
else
back_order = 0
View
17 core/spec/models/inventory_unit_spec.rb
@@ -1,7 +1,7 @@
require 'spec_helper'
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(:order) { mock_model(Order, :line_items => [line_item], :inventory_units => [], :shipments => mock('shipments'), :completed? => true) }
@@ -51,6 +51,15 @@
InventoryUnit.increase(order, variant, 5)
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
context "when :create_inventory_units is true" do
@@ -67,7 +76,7 @@
end
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
InventoryUnit.should_receive(:create_units).with(order, variant, 2, 3)
@@ -76,7 +85,7 @@
end
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
InventoryUnit.should_receive(:create_units).with(order, variant, 0, 5)
@@ -85,7 +94,7 @@
end
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
InventoryUnit.should_receive(:create_units).with(order, variant, 0, 5)
Please sign in to comment.
Something went wrong with that request. Please try again.