mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Retrieve the shipping tax on the order instead of calculating it from scratch
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user