mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add spec for calculating shipping tax. Fix incorrect formula.
This commit is contained in:
@@ -51,15 +51,23 @@ module OpenFoodNetwork
|
||||
end
|
||||
|
||||
def shipping_tax_on(shipping_cost)
|
||||
if Spree::Config[:shipment_inc_vat] && shipping_cost != nil
|
||||
shipping_cost * Spree::Config[:shipping_tax_rate]
|
||||
if shipment_inc_vat && shipping_cost.present?
|
||||
(shipping_cost * shipping_tax_rate / (1 + shipping_tax_rate)).round(2)
|
||||
else
|
||||
0.0
|
||||
0
|
||||
end
|
||||
end
|
||||
|
||||
def tax_rate_on(line_item)
|
||||
Spree::TaxRate.find_by_tax_category_id(line_item.variant.product.tax_category_id).andand.amount
|
||||
end
|
||||
|
||||
def shipment_inc_vat
|
||||
Spree::Config.shipment_inc_vat
|
||||
end
|
||||
|
||||
def shipping_tax_rate
|
||||
Spree::Config.shipping_tax_rate
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,10 +2,11 @@ require 'open_food_network/sales_tax_report'
|
||||
|
||||
module OpenFoodNetwork
|
||||
describe SalesTaxReport do
|
||||
let(:report) { SalesTaxReport.new(nil) }
|
||||
|
||||
describe "calculating totals for line items" do
|
||||
let(:li1) { double(:line_item, quantity: 1, amount: 12) }
|
||||
let(:li2) { double(:line_item, quantity: 2, amount: 24) }
|
||||
let(:report) { SalesTaxReport.new(nil) }
|
||||
let(:totals) { report.send(:totals_of, [li1, li2]) }
|
||||
|
||||
before do
|
||||
@@ -46,5 +47,24 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user