Find line items with and without tax

This commit is contained in:
Rohan Mitchell
2015-05-15 11:49:24 +10:00
parent 5660e3737e
commit ca1d88d8b1
2 changed files with 25 additions and 0 deletions

View File

@@ -23,6 +23,15 @@ Spree::LineItem.class_eval do
where('spree_products.supplier_id IN (?)', enterprises)
}
scope :with_tax, joins(:adjustments).
where('spree_adjustments.originator_type = ?', 'Spree::TaxRate').
select('DISTINCT spree_line_items.*')
# Line items without a Spree::TaxRate-originated adjustment
scope :without_tax, joins("LEFT OUTER JOIN spree_adjustments ON (spree_adjustments.adjustable_id=spree_line_items.id AND spree_adjustments.adjustable_type = 'Spree::LineItem' AND spree_adjustments.originator_type='Spree::TaxRate')").
where('spree_adjustments.id IS NULL')
def price_with_adjustments
# EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
# so line_item.adjustments returns an empty array

View File

@@ -24,6 +24,22 @@ module Spree
LineItem.supplied_by_any([s2]).should == [li2]
LineItem.supplied_by_any([s1, s2]).sort.should == [li1, li2].sort
end
describe "finding line items with and without tax" do
let(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new) }
let!(:adjustment1) { create(:adjustment, adjustable: li1, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
let!(:adjustment2) { create(:adjustment, adjustable: li1, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
before { li1; li2 }
it "finds line items with tax" do
LineItem.with_tax.should == [li1]
end
it "finds line items without tax" do
LineItem.without_tax.should == [li2]
end
end
end
describe "calculating price with adjustments" do