Retrieve the shipping tax on the order instead of calculating it from scratch

This commit is contained in:
Rohan Mitchell
2015-03-20 11:15:49 +11:00
parent 7fb8370c36
commit daa30ed518
3 changed files with 5 additions and 28 deletions

View File

@@ -16,7 +16,7 @@ module OpenFoodNetwork
@orders.map do |order|
totals = totals_of order.line_items
shipping_cost = shipping_cost_for order
shipping_tax = shipping_tax_on shipping_cost
shipping_tax = order.shipping_tax
[order.number, order.created_at, totals[:items], totals[:items_total],
totals[:taxable_total], totals[:sales_tax], shipping_cost, shipping_tax, totals[:sales_tax] + shipping_tax,
@@ -54,14 +54,6 @@ module OpenFoodNetwork
shipping_cost = shipping_cost.nil? ? 0.0 : shipping_cost
end
def shipping_tax_on(shipping_cost)
if shipment_inc_vat && shipping_cost.present?
(shipping_cost * shipping_tax_rate / (1 + shipping_tax_rate)).round(2)
else
0
end
end
def tax_included_in(line_item)
line_item.adjustments.included_tax.sum &:amount
end

View File

@@ -109,6 +109,8 @@ feature %q{
end
describe "Sales tax report" do
let!(:payment_method) { create(:payment_method, distributors: [user1.enterprises.first]) }
let(:user1) do
create_enterprise_user(enterprises: [create(:distributor_enterprise)])
end
@@ -134,6 +136,8 @@ feature %q{
before do
Spree::Config.shipment_inc_vat = true
Spree::Config.shipping_tax_rate = 0.2
order1.create_shipment!
order1.finalize!
login_to_admin_as user1

View File

@@ -56,24 +56,5 @@ module OpenFoodNetwork
end
end
end
describe "calculating the shipping tax on a shipping cost" do
it "returns zero when shipping does not include VAT" do
report.stub(:shipment_inc_vat) { false }
report.send(:shipping_tax_on, 12).should == 0
end
it "returns zero when no shipping cost is passed" do
report.stub(:shipment_inc_vat) { true }
report.send(:shipping_tax_on, nil).should == 0
end
it "returns the tax included in the price otherwise" do
report.stub(:shipment_inc_vat) { true }
report.stub(:shipping_tax_rate) { 0.2 }
report.send(:shipping_tax_on, 12).should == 2
end
end
end
end