Admin can modify a taxed adjustment on an order

This commit is contained in:
Rohan Mitchell
2015-11-04 11:56:16 +11:00
parent 85e45fa558
commit 727ecae62b
4 changed files with 68 additions and 1 deletions

View File

@@ -2,9 +2,17 @@ module Spree
module Admin
AdjustmentsController.class_eval do
before_filter :set_included_tax, only: :create
before_filter :set_default_tax_rate, only: :edit
private
def set_default_tax_rate
if @adjustment.included_tax > 0 && TaxRate.count == 1
@tax_rate_id = TaxRate.first.id
end
end
def set_included_tax
if params[:tax_rate_id].present?
tax_rate = TaxRate.find params[:tax_rate_id]

View File

@@ -0,0 +1,25 @@
.row
.alpha.three.columns
= f.field_container :amount do
= f.label :amount, raw(t(:amount) + content_tag(:span, " *", :class => "required"))
= text_field :adjustment, :amount, :class => 'fullwidth'
= f.error_message_on :amount
.three.columns
= f.field_container :included_tax do
= f.label :included_tax, t(:included_tax)
= text_field :adjustment, :included_tax, disabled: true, class: 'fullwidth'
= f.error_message_on :included_tax
.omega.three.columns
= f.field_container :tax_rate_id do
= f.label :tax_rate_id, t(:tax)
= select_tag :tax_rate_id, options_from_collection_for_select(Spree::TaxRate.all, :id, :name, @tax_rate_id), prompt: t(:remove_tax), class: 'select2 fullwidth'
= f.error_message_on :tax_rate_id
.row
.alpha.omega.twelve.columns
= f.field_container :label do
= f.label :label, raw(t(:description) + content_tag(:span, " *", :class => "required"))
= text_field :adjustment, :label, :class => 'fullwidth'
= f.error_message_on :label

View File

@@ -38,4 +38,5 @@ en:
footer_about_url: "About URL"
footer_tos_url: "Terms of Service URL"
invoice: "Invoice"
included_tax: "Included tax"
included_tax: "Included tax"
remove_tax: "Remove tax"

View File

@@ -129,6 +129,39 @@ feature %q{
page.should have_selector 'td.included-tax', text: '10'
end
scenario "modifying taxed adjustments on an order" do
# Given a tax rate and a taxed adjustment
tax_rate = create(:tax_rate, name: 'GST', calculator: build(:calculator, preferred_amount: 10))
adjustment = create(:adjustment, adjustable: @order, amount: 110, included_tax: 10)
# When I go to the adjustments page for the order
login_to_admin_section
visit spree.admin_orders_path
page.find('td.actions a.icon-edit').click
click_link 'Adjustments'
page.find('td.actions a.icon-edit').click
# Then I should see the uneditable included tax and our tax rate as the default
page.should have_field :adjustment_included_tax, with: '10.00', disabled: true
page.should have_select :tax_rate_id, selected: 'GST'
# When I edit the adjustment, removing the tax
select 'Remove tax', from: :tax_rate_id
click_button 'Continue'
# Then the adjustment tax should be cleared
page.should have_selector 'td.amount', text: '110'
page.should have_selector 'td.included-tax', text: '0'
end
scenario "modifying an untaxed adjustment on an order" do
# Given a tax rate and an untaxed adjustment
# When I go to the adjustments page for the order
# Then I should see 'Remove tax' as the default tax rate
# When I edit the adjustment, setting a tax rate
# Then the adjustment tax should be recalculated
end
context "as an enterprise manager" do
let(:coordinator1) { create(:distributor_enterprise) }