From 727ecae62b8b8299c151301d4f4b47cb21749b47 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Wed, 4 Nov 2015 11:56:16 +1100 Subject: [PATCH] Admin can modify a taxed adjustment on an order --- .../admin/adjustments_controller_decorator.rb | 8 +++++ .../admin/adjustments/_edit_form.html.haml | 25 ++++++++++++++ config/locales/en.yml | 3 +- spec/features/admin/orders_spec.rb | 33 +++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 app/views/spree/admin/adjustments/_edit_form.html.haml diff --git a/app/controllers/spree/admin/adjustments_controller_decorator.rb b/app/controllers/spree/admin/adjustments_controller_decorator.rb index 23cce4a623..1414a330a2 100644 --- a/app/controllers/spree/admin/adjustments_controller_decorator.rb +++ b/app/controllers/spree/admin/adjustments_controller_decorator.rb @@ -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] diff --git a/app/views/spree/admin/adjustments/_edit_form.html.haml b/app/views/spree/admin/adjustments/_edit_form.html.haml new file mode 100644 index 0000000000..98e02ce555 --- /dev/null +++ b/app/views/spree/admin/adjustments/_edit_form.html.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index 600b21321f..08dde26cd8 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -38,4 +38,5 @@ en: footer_about_url: "About URL" footer_tos_url: "Terms of Service URL" invoice: "Invoice" - included_tax: "Included tax" \ No newline at end of file + included_tax: "Included tax" + remove_tax: "Remove tax" diff --git a/spec/features/admin/orders_spec.rb b/spec/features/admin/orders_spec.rb index 2a3464abf9..59fc205690 100644 --- a/spec/features/admin/orders_spec.rb +++ b/spec/features/admin/orders_spec.rb @@ -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) }