From 53fa71d1f334c268dbd78a2c5607fa3891faad26 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Thu, 26 Feb 2015 09:20:35 +1100 Subject: [PATCH] Admin can set enterprise fee's tax category --- app/controllers/admin/enterprise_fees_controller.rb | 1 + app/models/enterprise_fee.rb | 2 +- app/presenters/enterprise_fee_presenter.rb | 2 +- app/views/admin/enterprise_fees/index.html.haml | 2 ++ app/views/admin/enterprise_fees/index.rep | 1 + spec/features/admin/enterprise_fees_spec.rb | 12 ++++++++++-- 6 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/admin/enterprise_fees_controller.rb b/app/controllers/admin/enterprise_fees_controller.rb index 085828d7b3..c4d4a621b1 100644 --- a/app/controllers/admin/enterprise_fees_controller.rb +++ b/app/controllers/admin/enterprise_fees_controller.rb @@ -59,6 +59,7 @@ module Admin def load_data @calculators = EnterpriseFee.calculators.sort_by(&:name) + @tax_categories = Spree::TaxCategory.order('is_default DESC, name ASC') end def collection diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 23ea158181..730bac0787 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -9,7 +9,7 @@ class EnterpriseFee < ActiveRecord::Base calculated_adjustments - attr_accessible :enterprise_id, :fee_type, :name, :calculator_type + attr_accessible :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type FEE_TYPES = %w(packing transport admin sales fundraising) PER_ORDER_CALCULATORS = ['Spree::Calculator::FlatRate', 'Spree::Calculator::FlexiRate'] diff --git a/app/presenters/enterprise_fee_presenter.rb b/app/presenters/enterprise_fee_presenter.rb index a0a6d8460a..b8f9ae4655 100644 --- a/app/presenters/enterprise_fee_presenter.rb +++ b/app/presenters/enterprise_fee_presenter.rb @@ -3,7 +3,7 @@ class EnterpriseFeePresenter @controller, @enterprise_fee, @index = controller, enterprise_fee, index end - delegate :id, :enterprise_id, :fee_type, :name, :calculator_type, :to => :enterprise_fee + delegate :id, :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type, :to => :enterprise_fee def enterprise_fee @enterprise_fee diff --git a/app/views/admin/enterprise_fees/index.html.haml b/app/views/admin/enterprise_fees/index.html.haml index ba3c3e6f4c..2237ca8a43 100644 --- a/app/views/admin/enterprise_fees/index.html.haml +++ b/app/views/admin/enterprise_fees/index.html.haml @@ -13,6 +13,7 @@ %th Enterprise %th Fee Type %th Name + %th Tax Category %th Calculator %th Calculator values %th.actions @@ -24,6 +25,7 @@ = f.ng_collection_select :enterprise_id, @enterprises, :id, :name, 'enterprise_fee.enterprise_id', :include_blank => true %td= f.ng_select :fee_type, enterprise_fee_type_options, 'enterprise_fee.fee_type' %td= f.ng_text_field :name, { placeholder: 'e.g. packing fee' } + %td= f.ng_collection_select :tax_category_id, @tax_categories, :id, :name, 'enterprise_fee.tax_category_id' %td= f.ng_collection_select :calculator_type, @calculators, :name, :description, 'enterprise_fee.calculator_type', {'class' => 'calculator_type', 'ng-model' => 'calculatorType', 'spree-ensure-calculator-preferences-match-type' => "1"} %td{'ng-bind-html-unsafe-compiled' => 'enterprise_fee.calculator_settings'} %td.actions{'spree-delete-resource' => "1"} diff --git a/app/views/admin/enterprise_fees/index.rep b/app/views/admin/enterprise_fees/index.rep index 61192ca786..8dc24b5d74 100644 --- a/app/views/admin/enterprise_fees/index.rep +++ b/app/views/admin/enterprise_fees/index.rep @@ -4,6 +4,7 @@ r.list_of :enterprise_fees, @presented_collection do r.element :enterprise_name r.element :fee_type r.element :name + r.element :tax_category_id r.element :calculator_type r.element :calculator_description r.element :calculator_settings if @include_calculators diff --git a/spec/features/admin/enterprise_fees_spec.rb b/spec/features/admin/enterprise_fees_spec.rb index 44f26deddd..36fe1b76ac 100644 --- a/spec/features/admin/enterprise_fees_spec.rb +++ b/spec/features/admin/enterprise_fees_spec.rb @@ -6,9 +6,12 @@ feature %q{ }, js: true do include AuthenticationWorkflow include WebHelper - + + let!(:tax_category_gst) { create(:tax_category, name: 'GST') } + let!(:tax_category_gst_exempt) { create(:tax_category, name: 'GST exempt') } + scenario "listing enterprise fees" do - fee = create(:enterprise_fee, name: '$0.50 / kg', fee_type: 'packing') + fee = create(:enterprise_fee, name: '$0.50 / kg', fee_type: 'packing', tax_category: tax_category_gst) amount = fee.calculator.preferred_amount login_to_admin_section @@ -18,6 +21,7 @@ feature %q{ page.should have_selector "#enterprise_fee_set_collection_attributes_0_enterprise_id" page.should have_selector "option[selected]", text: 'Packing' page.should have_selector "input[value='$0.50 / kg']" + page.should have_selector "option[selected]", text: 'GST' page.should have_selector "option[selected]", text: 'Flat Rate (per item)' page.should have_selector "input[value='#{amount}']" end @@ -35,6 +39,7 @@ feature %q{ select 'Feedme', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id' select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type' fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Hello!' + select 'GST', from: 'enterprise_fee_set_collection_attributes_0_tax_category_id' select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type' click_button 'Update' @@ -64,6 +69,7 @@ feature %q{ select 'Foo', from: 'enterprise_fee_set_collection_attributes_0_enterprise_id' select 'Admin', from: 'enterprise_fee_set_collection_attributes_0_fee_type' fill_in 'enterprise_fee_set_collection_attributes_0_name', with: 'Greetings!' + select 'GST exempt', from: 'enterprise_fee_set_collection_attributes_0_tax_category_id' select 'Flat Percent', from: 'enterprise_fee_set_collection_attributes_0_calculator_type' click_button 'Update' @@ -71,6 +77,7 @@ feature %q{ page.should have_selector "option[selected]", text: 'Foo' page.should have_selector "option[selected]", text: 'Admin' page.should have_selector "input[value='Greetings!']" + page.should have_selector "option[selected]", text: 'GST exempt' page.should have_selector "option[selected]", text: 'Flat Percent' end @@ -137,6 +144,7 @@ feature %q{ select distributor1.name, :from => 'enterprise_fee_set_collection_attributes_0_enterprise_id' fill_in 'enterprise_fee_set_collection_attributes_0_name', :with => 'foo' + select 'GST', from: 'enterprise_fee_set_collection_attributes_0_tax_category_id' select 'Flat Percent', :from => 'enterprise_fee_set_collection_attributes_0_calculator_type' click_button 'Update'