Admin can set enterprise fee's tax category

This commit is contained in:
Rohan Mitchell
2015-02-26 09:20:35 +11:00
parent 61c08997a1
commit 53fa71d1f3
6 changed files with 16 additions and 4 deletions

View File

@@ -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

View File

@@ -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']

View File

@@ -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

View File

@@ -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"}

View File

@@ -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

View File

@@ -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'