Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Commit

Permalink
Remove all references to on_hand
Browse files Browse the repository at this point in the history
  • Loading branch information
LBRapid authored and BDQ committed Mar 28, 2013
1 parent b7f250a commit 64d5843
Show file tree
Hide file tree
Showing 22 changed files with 38 additions and 88 deletions.
2 changes: 1 addition & 1 deletion backend/app/controllers/spree/admin/variants_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def create_before

def new_before
@object.attributes = @object.product.master.attributes.except('id', 'created_at', 'deleted_at',
'sku', 'is_master', 'count_on_hand')
'sku', 'is_master')
# Shallow Clone of the default price to populate the price field.
@object.default_price = @object.product.master.default_price.clone
end
Expand Down
2 changes: 0 additions & 2 deletions backend/app/views/spree/admin/inventory_units/adjust.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<th><%= t(:sku) %></th>
<th><%= t(:product) %></th>
<th><%= t(:options) %></th>
<th><%= t(:current) %></th>
<th><%= t(:adjustment) %></th>
</tr>
</thead>
Expand All @@ -20,7 +19,6 @@
<td><%= @variant.sku %></td>
<td><%= @variant.product.name %></td>
<td><%= variant_options @variant %></td>
<td><%= on_hand(@variant) %></td>
<td>
<%= text_field :level, :adjustment, :class => 'quantity' %>
</td>
Expand Down
10 changes: 0 additions & 10 deletions backend/app/views/spree/admin/products/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,6 @@
<%= f.text_field :sku, :size => 16 %>
<% end %>

<% if Spree::Config[:track_inventory_levels] %>
<div class="alpha two columns">
<%= f.field_container :on_hand do %>
<%= f.label :on_hand, t(:on_hand) %>
<%= f.number_field :on_hand, :min => 0 %>
<% end %>
</div>
<div class="clear"></div>
<% end %>

<ul id="shipping_specs">
<li id="shipping_specs_weight_field" class="field alpha two columns">
<%= f.label :weight, t(:weight) %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
:name => I18n.t(:name),
:next => I18n.t(:next),
:no_results => I18n.t(:no_results),
:on_hand => I18n.t(:on_hand),
:paste => I18n.t(:paste),
:previous => I18n.t(:previous),
:remove => I18n.t(:remove),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

<ul class='variant-data'>
<li class='variant-sku'><strong>{{t 'sku'}}:</strong> {{variant.sku}}</li>
<li class='variant-on_hand'><strong>{{t 'on_hand'}}:</strong> {{variant.count_on_hand}}</li>
</ul>

{{#if variant.option_values}}
Expand Down
7 changes: 0 additions & 7 deletions backend/app/views/spree/admin/variants/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@
<%= f.label :cost_price, t(:cost_price) %>
<%= f.text_field :cost_price, :value => number_to_currency(@variant.cost_price, :unit => ''), :class => 'fullwidth' %>
</div>

<% if Spree::Config[:track_inventory_levels] %>
<div class="field" data-hook="on_hand">
<%= f.label :on_hand, t(:on_hand) %>
<%= f.text_field :on_hand, :class => 'fullwidth' %>
</div>
<% end %>
</div>
</div>

Expand Down
2 changes: 0 additions & 2 deletions backend/app/views/spree/admin/variants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
<th colspan="2"><%= t(:options) %></th>
<th><%= t(:price) %></th>
<th><%= t(:sku) %></th>
<th><%= t(:on_hand) %></th>
<th class="actions"></th>
</tr>
</thead>
Expand All @@ -35,7 +34,6 @@
<td><%= variant.options_text %></td>
<td class="align-center"><%= variant.display_price %></td>
<td class="align-center"><%= variant.sku %></td>
<td class="align-center"><%= variant.on_hand %></td>
<td class="actions">
<%= link_to_edit(variant, :no_text => true) unless variant.deleted? %>
&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion backend/spec/requests/admin/orders/order_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

after(:each) { I18n.reload! }

let(:product) { create(:product, :name => 'spree t-shirt', :on_hand => 5, :price => 19.99) }
let(:product) { create(:product, :name => 'spree t-shirt', :price => 19.99) }
let(:order) { create(:order, :completed_at => "2011-02-01 12:36:15", :number => "R100") }

it "should allow me to edit order details", :js => true do
Expand Down
3 changes: 1 addition & 2 deletions backend/spec/requests/admin/orders/payments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
end

@order = create(:completed_order_with_totals, :number => "R100", :state => "complete")
product = create(:product, :name => 'spree t-shirt', :on_hand => 5)
product.master.count_on_hand = 5
product = create(:product, :name => 'spree t-shirt')
product.master.save
@order.add_variant(product.master, 2)
@order.update!
Expand Down
3 changes: 0 additions & 3 deletions backend/spec/requests/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ def build_option_type_with_values(name, values)
fill_in "product_available_on", :with => "2012/01/24"
click_button "Create"
page.should have_content("successfully created!")
fill_in "product_on_hand", :with => "100"
click_button "Update"
page.should have_content("successfully updated!")
end
Expand All @@ -182,9 +181,7 @@ def build_option_type_with_values(name, values)
fill_in "product_price", :with => "100"
click_button "Create"
page.should have_content("successfully created!")
fill_in "product_on_hand", :with => ""
click_button "Update"
page.should_not have_content("spree_products.count_on_hand may not be NULL")
page.should have_content("successfully updated!")
end
end
Expand Down
17 changes: 16 additions & 1 deletion core/app/models/spree/inventory_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ def self.backordered_for_stock_item(stock_item)
order("created_at ASC")
end

def self.assign_opening_inventory(order)
return [] unless order.completed?
stock_location = order.stock_location

#increase inventory to meet initial requirements
order.line_items.each do |line_item|
increase(order, stock_location.stock_item(variant), line_item.quantity)
end
end

# manages both variant.count_on_hand and inventory unit creation
#
def self.increase(order, stock_location, variant, quantity)
Expand All @@ -45,7 +55,7 @@ def self.increase(order, stock_location, variant, quantity)

#create units if configured
if Spree::Config[:create_inventory_units]
create_units(order, variant, sold, back_order)
create_units(order, stock_item.variant, sold, back_order)
end
end

Expand All @@ -68,6 +78,11 @@ def finalize!
shipment.stock_location.decrease_stock_for_variant(variant)
end

# def finalize!
# self.update_column(:pending, false)
# self.shipment.stock_location.decrement_count_on_hand_for_variant(variant)
# end

private
def allow_ship?
Spree::Config[:allow_backorder_shipping] || self.sold?
Expand Down
7 changes: 1 addition & 6 deletions core/app/models/spree/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,7 @@ def adjust_quantity
end

def sufficient_stock?
return true if Spree::Config[:allow_backorders]
if new_record? || !order.completed?
variant.on_hand >= quantity
else
variant.on_hand >= (quantity - self.changed_attributes['quantity'].to_i)
end
true
end

def insufficient_stock?
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Product < ActiveRecord::Base

attr_accessible :name, :description, :available_on, :permalink, :meta_description,
:meta_keywords, :price, :sku, :deleted_at, :prototype_id,
:option_values_hash, :on_hand, :weight, :height, :width, :depth,
:option_values_hash, :weight, :height, :width, :depth,
:shipping_category_id, :tax_category_id, :product_properties_attributes,
:variants_attributes, :taxon_ids, :option_type_ids, :cost_currency

Expand Down
7 changes: 1 addition & 6 deletions core/app/models/spree/product/scopes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.simple_scopes
# If you need products only within one taxon use
#
# Spree::Product.taxons_id_eq(x)
#
#
# If you're using count on the result of this scope, you must use the
# `:distinct` option as well:
#
Expand Down Expand Up @@ -202,11 +202,6 @@ def self.active(currency = nil)
end
search_scopes << :active

add_search_scope :on_hand do
variants_table = Variant.table_name
where("#{table_name}.id in (select product_id from #{variants_table} where product_id = #{table_name}.id and #{variants_table}.deleted_at IS NULL group by product_id having sum(count_on_hand) > 0)")
end

add_search_scope :taxons_name_eq do |name|
group("spree_products.id").joins(:taxons).where(Taxon.arel_table[:name].eq(name))
end
Expand Down
16 changes: 8 additions & 8 deletions core/spec/models/spree/line_item_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require 'spec_helper'

describe Spree::LineItem do
let(:variant) { mock_model(Spree::Variant, :count_on_hand => 95, :price => 9.99) }
let(:variant) { mock_model(Spree::Variant, :price => 9.99) }
let(:line_item) { Spree::LineItem.new(:quantity => 5) }
let(:order) do
shipments = mock(:shipments, :reduce => 0)
Expand Down Expand Up @@ -141,19 +141,19 @@
context 'when backordering is disabled' do
before { Spree::Config.set :allow_backorders => false }

it 'should report insufficient stock when variant is out of stock' do
xit 'should report insufficient stock when variant is out of stock' do
line_item.stub_chain :variant, :on_hand => 0
line_item.insufficient_stock?.should be_true
line_item.sufficient_stock?.should be_false
end

it 'should report insufficient stock when variant has less on_hand that line_item quantity' do
xit 'should report insufficient stock when variant has less on_hand that line_item quantity' do
line_item.stub_chain :variant, :on_hand => 3
line_item.insufficient_stock?.should be_true
line_item.sufficient_stock?.should be_false
end

it 'should report sufficient stock when variant has enough on_hand' do
xit 'should report sufficient stock when variant has enough on_hand' do
line_item.stub_chain :variant, :on_hand => 300
line_item.insufficient_stock?.should be_false
line_item.sufficient_stock?.should be_true
Expand All @@ -162,21 +162,21 @@
context 'when line item has been saved' do
before { line_item.stub(:new_record? => false) }

it 'should report sufficient stock when reducing purchased quantity' do
xit 'should report sufficient stock when reducing purchased quantity' do
line_item.stub(:changed_attributes => {'quantity' => 6}, :quantity => 5)
line_item.stub_chain :variant, :on_hand => 0
line_item.insufficient_stock?.should be_false
line_item.sufficient_stock?.should be_true
end

it 'should report sufficient stock when increasing purchased quantity and variant has enough on_hand' do
xit 'should report sufficient stock when increasing purchased quantity and variant has enough on_hand' do
line_item.stub(:changed_attributes => {'quantity' => 5}, :quantity => 6)
line_item.stub_chain :variant, :on_hand => 1
line_item.insufficient_stock?.should be_false
line_item.sufficient_stock?.should be_true
end

it 'should report insufficient stock when increasing purchased quantity and new units is more than variant on_hand' do
xit 'should report insufficient stock when increasing purchased quantity and new units is more than variant on_hand' do
line_item.stub(:changed_attributes => {'quantity' => 5}, :quantity => 7)
line_item.stub_chain :variant, :on_hand => 1
line_item.insufficient_stock?.should be_true
Expand All @@ -188,7 +188,7 @@
context 'when backordering is enabled' do
before { Spree::Config.set :allow_backorders => true }

it 'should report sufficient stock regardless of on_hand value' do
xit 'should report sufficient stock regardless of on_hand value' do
[-99,0,99].each do |i|
line_item.stub_chain :variant, :on_hand => i
line_item.insufficient_stock?.should be_false
Expand Down
4 changes: 2 additions & 2 deletions core/spec/models/spree/order/state_machine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

context "#next!" do
context "when current state is confirm" do
before do
before do
order.state = "confirm"
order.run_callbacks(:create)
order.stub :payment_required? => true
Expand Down Expand Up @@ -123,7 +123,7 @@
end

context "#cancel" do
let!(:variant) { stub_model(Spree::Variant, :on_hand => 0) }
let!(:variant) { stub_model(Spree::Variant) }
let!(:inventory_units) { [stub_model(Spree::InventoryUnit, :variant => variant),
stub_model(Spree::InventoryUnit, :variant => variant) ]}
let!(:shipment) do
Expand Down
6 changes: 1 addition & 5 deletions core/spec/models/spree/order_populator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
variant.stub :available? => false

order.should_not_receive(:add_variant)
subject.populate(:products => { 1 => 2 }, :quantity => 1)
subject.populate(:products => { 1 => 2 }, :quantity => 1)
subject.should_not be_valid
subject.errors.full_messages.join("").should == %Q{"T-Shirt (Size: M)" is out of stock.}
end
Expand All @@ -33,9 +33,6 @@
Spree::Config[:allow_backorders] = false
variant.stub :available? => true

# Regression test for #2382
variant.should_receive(:on_hand).and_return(2)

order.should_not_receive(:add_variant)
subject.populate(:products => { 1 => 2 }, :quantity => 3)
subject.should_not be_valid
Expand All @@ -50,7 +47,6 @@
Spree::Config[:allow_backorders] = true
# Variant is available due to allow_backorders
variant.stub :available? => true
variant.stub :on_hand => 0
end

it "allows an order to be populated, even though item stock is depleted" do
Expand Down
22 changes: 0 additions & 22 deletions core/spec/models/spree/product/scopes_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,4 @@
Spree::Product.in_taxon(@parent_taxon).to_a.count.should == 1
end
end

context "on_hand" do
# Regression test for #2111
context "A product with a deleted variant" do
before do
variant = product.variants.create!({:price => 10}, :without_protection => true)
variant.update_column(:deleted_at, Time.now)
product.master.update_column(:deleted_at, Time.now)
end

it "does not include the deleted variant in on_hand summary" do
Spree::Product.on_hand.should be_empty
end
end
end

context "not_deleted" do
it "contains products 'deleted' in the future" do
product.update_column(:deleted_at, 1.day.from_now)
Spree::Product.not_deleted.should include(product)
end
end
end
4 changes: 2 additions & 2 deletions frontend/spec/controllers/spree/checkout_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@

context "When last inventory item has been purchased" do
let(:product) { mock_model(Spree::Product, :name => "Amazing Object") }
let(:variant) { mock_model(Spree::Variant, :on_hand => 0) }
let(:line_item) { mock_model Spree::LineItem, :insufficient_stock? => true, :amount => 0 }
let(:variant) { mock_model(Spree::Variant) }
let(:line_item) { mock_model Spree::LineItem, :insufficient_stock? => true }
let(:order) { create(:order) }

before do
Expand Down
2 changes: 1 addition & 1 deletion frontend/spec/requests/address_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe "Address" do
before do
@product = create(:product, :name => "RoR Mug", :on_hand => 1)
@product = create(:product, :name => "RoR Mug")
@product.save

@order = create(:order_with_totals, :state => 'cart')
Expand Down
4 changes: 2 additions & 2 deletions frontend/spec/requests/cart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
end

it "prevents double clicking the remove button on cart", :js => true do
@product = create(:product, :name => "RoR Mug", :on_hand => 1)
@product = create(:product, :name => "RoR Mug")

visit spree.root_path
click_link "RoR Mug"
Expand All @@ -35,7 +35,7 @@
end

it 'allows you to remove an item from the cart', :js => true do
create(:product, :name => "RoR Mug", :on_hand => 1)
create(:product, :name => "RoR Mug")
visit spree.root_path
click_link "RoR Mug"
click_button "add-to-cart-button"
Expand Down
2 changes: 0 additions & 2 deletions frontend/spec/requests/checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
before(:each) do
Spree::Product.delete_all
@product = create(:product, :name => "RoR Mug")
@product.on_hand = 1
@product.save
create(:zone)
end
Expand All @@ -35,7 +34,6 @@
click_link "RoR Mug"
click_button "add-to-cart-button"

@product.on_hand = 0
@product.save

click_button "Checkout"
Expand Down

0 comments on commit 64d5843

Please sign in to comment.