Add LineItem#supplied_by scope, fixes orders and fulfillment report supplier filtering

This commit is contained in:
Rohan Mitchell
2013-09-27 14:11:12 +10:00
parent dac49d1044
commit 01036ec730
2 changed files with 22 additions and 0 deletions

View File

@@ -13,4 +13,9 @@ Spree::LineItem.class_eval do
select('spree_line_items.*')
end
}
scope :supplied_by, lambda { |enterprise|
joins(:product).
where('spree_products.supplier_id = ?', enterprise)
}
end

View File

@@ -2,5 +2,22 @@ require 'spec_helper'
module Spree
describe LineItem do
describe "scopes" do
it "finds line items for products supplied by a particular enterprise" do
o = create(:order)
s1 = create(:supplier_enterprise)
s2 = create(:supplier_enterprise)
p1 = create(:simple_product, supplier: s1)
p2 = create(:simple_product, supplier: s2)
li1 = create(:line_item, order: o, product: p1)
li2 = create(:line_item, order: o, product: p2)
LineItem.supplied_by(s1).should == [li1]
LineItem.supplied_by(s2).should == [li2]
end
end
end
end