Adding tax settings for billing enterprise users

This commit is contained in:
Rob Harrington
2015-09-11 14:55:36 +10:00
parent 01c9560a19
commit 5eb20fd8cd
5 changed files with 90 additions and 11 deletions

View File

@@ -7,6 +7,8 @@ Spree::AppConfiguration.class_eval do
# Tax Preferences
preference :products_require_tax_category, :boolean, default: false
preference :shipping_tax_rate, :decimal, default: 0
preference :account_bill_inc_tax, :boolean, default: false
preference :account_bill_tax_rate, :decimal, default: 0
# Accounts & Billing Preferences
preference :accounts_distributor_id, :integer, default: nil

View File

@@ -1,6 +0,0 @@
/ insert_before "[data-hook='shipment_vat']"
%div.field.align-center{ "data-hook" => "products_require_tax_category" }
= hidden_field_tag 'preferences[products_require_tax_category]', '0'
= check_box_tag 'preferences[products_require_tax_category]', '1', Spree::Config[:products_require_tax_category]
= label_tag nil, t(:products_require_tax_category)

View File

@@ -1,5 +0,0 @@
/ insert_after "[data-hook='shipment_vat']"
.field.align-center{ "data-hook" => "shipping_tax_rate" }
= number_field_tag "preferences[shipping_tax_rate]", Spree::Config[:shipping_tax_rate].to_f, in: 0.0..1.0, step: 0.01
= label_tag nil, t(:shipping_tax_rate)

View File

@@ -0,0 +1,32 @@
= render :partial => 'spree/admin/shared/configuration_menu'
- content_for :page_title do
= t(:tax_settings)
= form_tag admin_tax_settings_path, :method => :put do
.field.align-center{ "data-hook" => "products_require_tax_category" }
= hidden_field_tag 'preferences[products_require_tax_category]', '0'
= 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)
.field.align-center{ "data-hook" => "shipping_tax_rate" }
= number_field_tag "preferences[shipping_tax_rate]", Spree::Config[:shipping_tax_rate].to_f, in: 0.0..1.0, step: 0.01
= label_tag nil, t(:shipping_tax_rate)
.field.align-center{"data-hook" => "billing_tax"}
= hidden_field_tag 'preferences[account_bill_inc_tax]', '0'
= check_box_tag 'preferences[account_bill_inc_tax]', '1', Spree::Config[:account_bill_inc_tax]
= label_tag nil, t(:account_bill_inc_tax)
.field.align-center{ "data-hook" => "account_bill_tax_rate" }
= number_field_tag "preferences[account_bill_tax_rate]", Spree::Config[:account_bill_tax_rate].to_f, in: 0.0..1.0, step: 0.01
= label_tag nil, t(:account_bill_tax_rate)
.form-buttons{"data-hook" => "buttons"}
= button t(:update), 'icon-refresh'

View File

@@ -0,0 +1,56 @@
require 'spec_helper'
feature 'Account and Billing Settings' do
include AuthenticationWorkflow
include WebHelper
describe "updating" do
let!(:admin) { create(:admin_user) }
before do
Spree::Config.set({
products_require_tax_category: false,
shipment_inc_vat: false,
shipping_tax_rate: 0,
account_bill_inc_tax: false,
account_bill_tax_rate: 0
})
end
before do
quick_login_as_admin
end
context "as an admin user" do
it "loads the page" do
visit spree.admin_path
click_link "Configuration"
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'
expect(page).to have_field 'preferences_shipping_tax_rate'
expect(page).to have_unchecked_field 'preferences_account_bill_inc_tax'
expect(page).to have_field 'preferences_account_bill_tax_rate'
end
it "attributes can be changed" do
visit spree.edit_admin_tax_settings_path
check 'preferences_products_require_tax_category'
check 'preferences_shipment_inc_vat'
fill_in 'preferences_shipping_tax_rate', with: '0.12'
check 'preferences_account_bill_inc_tax'
fill_in 'preferences_account_bill_tax_rate', with: '0.05'
click_button "Update"
expect(Spree::Config.products_require_tax_category).to be true
expect(Spree::Config.shipment_inc_vat).to be true
expect(Spree::Config.shipping_tax_rate).to eq 0.12
expect(Spree::Config.account_bill_inc_tax).to be true
expect(Spree::Config.account_bill_tax_rate).to eq 0.05
end
end
end
end