From daa30ed518b6fec6c2f0608c28a4d805217cf9f4 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 20 Mar 2015 11:15:49 +1100 Subject: [PATCH] Retrieve the shipping tax on the order instead of calculating it from scratch --- lib/open_food_network/sales_tax_report.rb | 10 +--------- spec/features/admin/reports_spec.rb | 4 ++++ .../sales_tax_report_spec.rb | 19 ------------------- 3 files changed, 5 insertions(+), 28 deletions(-) diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index d5b69011d2..db3660c84b 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -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 diff --git a/spec/features/admin/reports_spec.rb b/spec/features/admin/reports_spec.rb index 28c1366f7a..89fe97357a 100644 --- a/spec/features/admin/reports_spec.rb +++ b/spec/features/admin/reports_spec.rb @@ -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 diff --git a/spec/lib/open_food_network/sales_tax_report_spec.rb b/spec/lib/open_food_network/sales_tax_report_spec.rb index 043eac6ae7..00640d8f08 100644 --- a/spec/lib/open_food_network/sales_tax_report_spec.rb +++ b/spec/lib/open_food_network/sales_tax_report_spec.rb @@ -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