From 01e6397e2703aadd3777f9cd2be080b0b8c0ac52 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Tue, 6 Apr 2021 20:08:43 +0100 Subject: [PATCH] Remove Spree::Config[:shipment_inc_vat] This is now done per ShippingMethod instead of globally --- .../spree/admin/tax_settings_controller.rb | 5 +---- app/models/spree/app_configuration.rb | 1 - app/models/spree/shipping_rate.rb | 8 +------ .../spree/admin/tax_settings/edit.html.haml | 5 ----- .../admin/tax_settings_controller_spec.rb | 21 ++----------------- spec/features/admin/tax_settings_spec.rb | 8 +------ spec/models/spree/shipping_rate_spec.rb | 15 ++----------- 7 files changed, 7 insertions(+), 56 deletions(-) diff --git a/app/controllers/spree/admin/tax_settings_controller.rb b/app/controllers/spree/admin/tax_settings_controller.rb index ffc0a72b36..7ebeec543b 100644 --- a/app/controllers/spree/admin/tax_settings_controller.rb +++ b/app/controllers/spree/admin/tax_settings_controller.rb @@ -14,10 +14,7 @@ module Spree private def preferences_params - params.require(:preferences).permit( - :products_require_tax_category, - :shipment_inc_vat - ) + params.require(:preferences).permit(:products_require_tax_category) end end end diff --git a/app/models/spree/app_configuration.rb b/app/models/spree/app_configuration.rb index 53ae4bd5ab..c93488105f 100644 --- a/app/models/spree/app_configuration.rb +++ b/app/models/spree/app_configuration.rb @@ -58,7 +58,6 @@ module Spree preference :products_per_page, :integer, default: 12 preference :redirect_https_to_http, :boolean, default: false preference :require_master_price, :boolean, default: true - preference :shipment_inc_vat, :boolean, default: false # Request instructions/info for shipping preference :shipping_instructions, :boolean, default: false # Displays variant full price or difference with product price. diff --git a/app/models/spree/shipping_rate.rb b/app/models/spree/shipping_rate.rb index 857847b398..31fcec4c05 100644 --- a/app/models/spree/shipping_rate.rb +++ b/app/models/spree/shipping_rate.rb @@ -24,13 +24,7 @@ module Spree delegate :name, to: :shipping_method def display_price - price = if Spree::Config[:shipment_inc_vat] - (1 + Spree::TaxRate.default) * cost - else - cost - end - - Spree::Money.new(price, { currency: currency }) + Spree::Money.new(cost, { currency: currency }) end alias_method :display_cost, :display_price diff --git a/app/views/spree/admin/tax_settings/edit.html.haml b/app/views/spree/admin/tax_settings/edit.html.haml index 8d7afa0027..7ad2a3cdc7 100644 --- a/app/views/spree/admin/tax_settings/edit.html.haml +++ b/app/views/spree/admin/tax_settings/edit.html.haml @@ -10,10 +10,5 @@ = check_box_tag 'preferences[products_require_tax_category]', '1', Spree::Config[:products_require_tax_category] = label_tag nil, t(:products_require_tax_category) - .field.align-center{"data-hook" => "shipment_vat"} - = hidden_field_tag 'preferences[shipment_inc_vat]', '0' - = check_box_tag 'preferences[shipment_inc_vat]', '1', Spree::Config[:shipment_inc_vat] - = label_tag nil, t(:shipment_inc_vat) - .form-buttons{"data-hook" => "buttons"} = button t(:update), 'icon-refresh' diff --git a/spec/controllers/spree/admin/tax_settings_controller_spec.rb b/spec/controllers/spree/admin/tax_settings_controller_spec.rb index 134eb43b2a..dbb320b1c6 100644 --- a/spec/controllers/spree/admin/tax_settings_controller_spec.rb +++ b/spec/controllers/spree/admin/tax_settings_controller_spec.rb @@ -4,14 +4,7 @@ require 'spec_helper' describe Spree::Admin::TaxSettingsController, type: :controller do describe "#update" do - let(:params) { - { - preferences: { - products_require_tax_category: "1", - shipment_inc_vat: "0", - } - } - } + let(:params) { { preferences: { products_require_tax_category: "1" } } } before do allow(controller).to receive(:spree_current_user) { create(:admin_user) } @@ -20,17 +13,7 @@ describe Spree::Admin::TaxSettingsController, type: :controller do it "changes Tax settings" do expect { spree_post :update, params - }.to change { - [ - Spree::Config[:products_require_tax_category], - Spree::Config[:shipment_inc_vat], - ] - }.to( - [ - true, - false, - ] - ) + }.to change { Spree::Config[:products_require_tax_category] }.to(true) end end end diff --git a/spec/features/admin/tax_settings_spec.rb b/spec/features/admin/tax_settings_spec.rb index 43047bcdc2..e15c49b0df 100644 --- a/spec/features/admin/tax_settings_spec.rb +++ b/spec/features/admin/tax_settings_spec.rb @@ -8,10 +8,7 @@ feature 'Account and Billing Settings' do describe "updating" do before do - Spree::Config.set( - products_require_tax_category: false, - shipment_inc_vat: false, - ) + Spree::Config.set(products_require_tax_category: false) end context "as an admin user" do @@ -20,19 +17,16 @@ feature 'Account and Billing Settings' do click_link "Tax Settings" expect(page).to have_unchecked_field 'preferences_products_require_tax_category' - expect(page).to have_unchecked_field 'preferences_shipment_inc_vat' end it "attributes can be changed" do login_as_admin_and_visit spree.edit_admin_tax_settings_path check 'preferences_products_require_tax_category' - check 'preferences_shipment_inc_vat' click_button "Update" expect(Spree::Config.products_require_tax_category).to be true - expect(Spree::Config.shipment_inc_vat).to be true end end end diff --git a/spec/models/spree/shipping_rate_spec.rb b/spec/models/spree/shipping_rate_spec.rb index 03871722fe..d071b15c3c 100644 --- a/spec/models/spree/shipping_rate_spec.rb +++ b/spec/models/spree/shipping_rate_spec.rb @@ -10,21 +10,10 @@ describe Spree::ShippingRate do shipping_method: shipping_method, cost: 10.55) } - before { allow(Spree::TaxRate).to receive_messages(default: 0.05) } context "#display_price" do - context "when shipment includes VAT" do - before { Spree::Config[:shipment_inc_vat] = true } - it "displays the correct price" do - expect(shipping_rate.display_price.to_s).to eq "$11.08" # $10.55 * 1.05 == $11.08 - end - end - - context "when shipment does not include VAT" do - before { Spree::Config[:shipment_inc_vat] = false } - it "displays the correct price" do - expect(shipping_rate.display_price.to_s).to eq "$10.55" - end + it "displays the shipping price" do + expect(shipping_rate.display_price.to_s).to eq "$10.55" end context "when the currency is JPY" do