Skip to content

Commit

Permalink
Spree::Product.on_hand no longer sums deleted variants
Browse files Browse the repository at this point in the history
Fixes #2112
  • Loading branch information
radar committed Oct 18, 2012
1 parent 8c335ec commit aa367de
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/app/models/spree/product/scopes.rb
Expand Up @@ -199,7 +199,7 @@ def self.available(available_on = nil)

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 group by product_id having sum(count_on_hand) > 0)")
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|
Expand Down
14 changes: 14 additions & 0 deletions core/spec/models/product/scopes_spec.rb
Expand Up @@ -20,4 +20,18 @@
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({:count_on_hand => 300}, :without_protection => true)
variant.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
end

0 comments on commit aa367de

Please sign in to comment.