Record the tax included in shipping.

This commit is contained in:
Rohan Mitchell
2015-03-02 15:17:14 +11:00
parent 9395f6c808
commit dfb855bd14
4 changed files with 68 additions and 7 deletions

View File

@@ -0,0 +1,11 @@
module Spree
Shipment.class_eval do
def ensure_correct_adjustment_with_included_tax
ensure_correct_adjustment_without_included_tax
adjustment.set_included_tax! Config.shipping_tax_rate if Config.shipment_inc_vat
end
alias_method_chain :ensure_correct_adjustment, :included_tax
end
end

View File

@@ -1,5 +1,5 @@
class AddIncludedTaxToAdjustments < ActiveRecord::Migration
def change
add_column :spree_adjustments, :included_tax, :decimal, precision: 10, scale: 2
add_column :spree_adjustments, :included_tax, :decimal, precision: 10, scale: 2, null: false, default: 0
end
end

View File

@@ -416,7 +416,7 @@ ActiveRecord::Schema.define(:version => 20150225232938) do
t.string "originator_type"
t.boolean "eligible", :default => true
t.string "adjustable_type"
t.decimal "included_tax", :precision => 10, :scale => 2
t.decimal "included_tax", :precision => 10, :scale => 2, :default => 0.0, :null => false
end
add_index "spree_adjustments", ["adjustable_id"], :name => "index_adjustments_on_order_id"

View File

@@ -7,12 +7,12 @@ module Spree
describe "recording included tax" do
describe "TaxRate adjustments" do
let!(:zone) { create(:zone, default_tax: true) }
let!(:zone) { create(:zone, default_tax: true) }
let!(:zone_member) { ZoneMember.create!(zone: zone, zoneable: Country.find_by_name('Australia')) }
let!(:order) { create(:order) }
let!(:line_item) { create(:line_item, order: order) }
let(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::FlatRate.new(preferred_amount: 0.1)) }
let(:adjustment) { line_item.adjustments(:reload).first }
let!(:order) { create(:order) }
let!(:line_item) { create(:line_item, order: order) }
let(:tax_rate) { create(:tax_rate, included_in_price: true, calculator: Calculator::FlatRate.new(preferred_amount: 0.1)) }
let(:adjustment) { line_item.adjustments(:reload).first }
before do
order.reload
@@ -25,6 +25,56 @@ module Spree
end
end
describe "Shipment adjustments" do
let!(:order) { create(:order, shipping_method: shipping_method) }
let!(:line_item) { create(:line_item, order: order) }
let(:shipping_method) { create(:shipping_method, calculator: Calculator::FlatRate.new(preferred_amount: 50.0)) }
let(:adjustment) { order.adjustments(:reload).shipping.first }
it "has a shipping charge of $50" do
order.create_shipment!
adjustment.amount.should == 50
end
context "when tax on shipping is disabled" do
it "records 0% tax on shipment adjustments" do
Config.shipment_inc_vat = false
Config.shipping_tax_rate = 0
order.create_shipment!
adjustment.included_tax.should == 0
end
it "records 0% tax on shipments when a rate is set but shipment_inc_vat is false" do
Config.shipment_inc_vat = false
Config.shipping_tax_rate = 0.25
order.create_shipment!
adjustment.included_tax.should == 0
end
end
context "when tax on shipping is enabled" do
before do
Config.shipment_inc_vat = true
Config.shipping_tax_rate = 0.25
order.create_shipment!
end
it "takes the shipment adjustment tax included from the system setting" do
adjustment.included_tax.should == 12.50
end
it "records 0% tax on shipments when shipping_tax_rate is not set" do
Config.shipment_inc_vat = true
Config.shipping_tax_rate = nil
order.create_shipment!
adjustment.included_tax.should == 0
end
end
end
describe "setting the included tax by fraction" do
let(:adjustment) { Adjustment.new label: 'foo', amount: 123.45 }