diff --git a/app/models/spree/tax_rate_decorator.rb b/app/models/spree/tax_rate_decorator.rb index 652fb5b62b..a053394dbf 100644 --- a/app/models/spree/tax_rate_decorator.rb +++ b/app/models/spree/tax_rate_decorator.rb @@ -8,19 +8,18 @@ module Spree alias_method_chain :match, :sales_tax_registration end - def adjust_with_included_tax(order) adjust_without_included_tax(order) order.adjustments(:reload) order.line_items(:reload) - (order.adjustments.tax + order.price_adjustments).each do |a| - a.set_absolute_included_tax! a.amount + # TaxRate adjustments (order.adjustments.tax) and price adjustments (tax included on line items) consist of 100% tax + (order.adjustments.tax + order.price_adjustments).each do |adjustment| + adjustment.set_absolute_included_tax! adjustment.amount end end alias_method_chain :adjust, :included_tax - # Manually apply a TaxRate to a particular amount. TaxRates normally compute against # LineItems or Orders, so we mock out a line item here to fit the interface # that our calculator (usually DefaultTax) expects. @@ -40,7 +39,6 @@ module Spree end end - private def with_tax_included_in_price diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 83e854a08f..5c60a92778 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -7,7 +7,6 @@ # config.setting_name = 'new value' require 'spree/product_filters' -require 'spree/core/calculated_adjustments_decorator' require "#{Rails.root}/app/models/spree/payment_method_decorator" require "#{Rails.root}/app/models/spree/gateway_decorator" diff --git a/lib/spree/core/calculated_adjustments_decorator.rb b/lib/spree/core/calculated_adjustments_decorator.rb deleted file mode 100644 index 592bf59854..0000000000 --- a/lib/spree/core/calculated_adjustments_decorator.rb +++ /dev/null @@ -1,16 +0,0 @@ -module Spree - module Core - module CalculatedAdjustments - class << self - def included_with_explicit_class_name(klass) - included_without_explicit_class_name(klass) - - klass.class_eval do - has_one :calculator, as: :calculable, dependent: :destroy, class_name: 'Spree::Calculator' - end - end - alias_method_chain :included, :explicit_class_name - end - end - end -end diff --git a/spec/factories.rb b/spec/factories.rb index 280c378c42..e5f785b439 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -378,7 +378,7 @@ FactoryBot.define do shipping_method { create(:shipping_method) } end after(:create) do |shipment, evaluator| - shipment.shipping_rates.destroy_all # remove existing shipping_rates from shipment + shipment.shipping_rates.destroy_all shipment.add_shipping_method(evaluator.shipping_method, true) end end @@ -390,7 +390,7 @@ FactoryBot.define do after(:create) do |shipment, evaluator| shipping_method = create(:shipping_method_with, :shipping_fee, shipping_fee: evaluator.shipping_fee) - shipment.shipping_rates.destroy_all # remove existing shipping_rates from shipment + shipment.shipping_rates.destroy_all shipment.add_shipping_method(shipping_method, true) end end diff --git a/spec/models/spree/adjustment_spec.rb b/spec/models/spree/adjustment_spec.rb index 1771078cfb..06bbdc9274 100644 --- a/spec/models/spree/adjustment_spec.rb +++ b/spec/models/spree/adjustment_spec.rb @@ -61,38 +61,43 @@ module Spree describe "Shipment adjustments" do let(:shipping_method) { create(:shipping_method_with, :flat_rate) } let(:shipment) { create(:shipment_with, :shipping_method, shipping_method: shipping_method) } - let!(:order) { create(:order, distributor: hub, shipments: [shipment]) } + let(:order) { create(:order, distributor: hub) } let(:hub) { create(:distributor_enterprise, charges_sales_tax: true) } - let!(:line_item) { create(:line_item, order: order) } + let(:line_item) { create(:line_item, order: order) } let(:adjustment) { order.adjustments(:reload).shipping.first } - it "has a shipping charge of $50" do - adjustment.amount.should == 50 + describe "the shipping charge" do + it "is the adjustment amount" do + order.shipments = [shipment] + + adjustment.amount.should == 50 + end end describe "when tax on shipping is disabled" do + before { Config.shipment_inc_vat = false } it "records 0% tax on shipment adjustments" do - Config.shipment_inc_vat = false Config.shipping_tax_rate = 0 + order.shipments = [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.shipments = [shipment] adjustment.included_tax.should == 0 end end describe "when tax on shipping is enabled" do - before do - Config.shipment_inc_vat = true - Config.shipping_tax_rate = 0.25 - end + before { Config.shipment_inc_vat = true } it "takes the shipment adjustment tax included from the system setting" do + Config.shipping_tax_rate = 0.25 + order.shipments = [shipment] + # Finding the tax included in an amount that's already inclusive of tax: # total - ( total / (1 + rate) ) # 50 - ( 50 / (1 + 0.25) ) @@ -101,14 +106,15 @@ module Spree 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.shipments = [shipment] adjustment.included_tax.should == 0 end it "records 0% tax on shipments when the distributor does not charge sales tax" do order.distributor.update_attributes! charges_sales_tax: false + order.shipments = [shipment] adjustment.included_tax.should == 0 end