diff --git a/app/controllers/spree/admin/adjustments_controller.rb b/app/controllers/spree/admin/adjustments_controller.rb index f4fccde7ca..d5729a3477 100644 --- a/app/controllers/spree/admin/adjustments_controller.rb +++ b/app/controllers/spree/admin/adjustments_controller.rb @@ -18,7 +18,12 @@ module Spree end def collection - parent.all_adjustments.eligible + order_adjustments = parent.adjustments.where.not(originator_type: 'EnterpriseFee') + admin_adjustments = parent.adjustments.admin + payment_fees = parent.all_adjustments.payment_fee.eligible + shipping_fees = parent.all_adjustments.shipping + + order_adjustments.or(admin_adjustments) | payment_fees.or(shipping_fees) end def find_resource diff --git a/app/models/spree/adjustment.rb b/app/models/spree/adjustment.rb index 405775474e..c3efde7ab5 100644 --- a/app/models/spree/adjustment.rb +++ b/app/models/spree/adjustment.rb @@ -118,6 +118,10 @@ module Spree Spree::Money.new(amount, currency: currency) end + def admin? + originator_type.nil? + end + def immutable? state != "open" end diff --git a/app/views/spree/admin/adjustments/_edit_form.html.haml b/app/views/spree/admin/adjustments/_edit_form.html.haml index 918a9b5b6f..58d2db990d 100644 --- a/app/views/spree/admin/adjustments/_edit_form.html.haml +++ b/app/views/spree/admin/adjustments/_edit_form.html.haml @@ -5,18 +5,19 @@ = text_field :adjustment, :amount, :class => 'fullwidth' = f.error_message_on :amount - .four.columns - = f.field_container :included_tax do - = f.label :included_tax, t(:included_tax) - = f.text_field :included_tax, disabled: true, class: 'fullwidth', - value: number_with_precision(f.object.included_tax, precision: 2) - = f.error_message_on :included_tax + - if @adjustment.admin? + .four.columns + = f.field_container :included_tax do + = f.label :included_tax, t(:included_tax) + = f.text_field :included_tax, disabled: true, class: 'fullwidth', + value: number_with_precision(f.object.included_tax, precision: 2) + = f.error_message_on :included_tax - .omega.four.columns - = f.field_container :tax_rate_id do - = f.label :tax_rate_id, t(:tax_rate) - = 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 + .omega.four.columns + = f.field_container :tax_rate_id do + = f.label :tax_rate_id, t(:tax_rate) + = 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 diff --git a/spec/controllers/spree/admin/adjustments_controller_spec.rb b/spec/controllers/spree/admin/adjustments_controller_spec.rb index b96d173a6f..d36842e7ad 100644 --- a/spec/controllers/spree/admin/adjustments_controller_spec.rb +++ b/spec/controllers/spree/admin/adjustments_controller_spec.rb @@ -9,20 +9,37 @@ module Spree before { controller_login_as_admin } describe "index" do - let!(:order) { create(:order) } + let!(:order) { create(:completed_order_with_totals) } let!(:adjustment1) { - create(:adjustment, originator_type: "Spree::ShippingMethod", order: order) + create(:adjustment, originator_type: "Spree::ShippingMethod", order: order, + adjustable: order.shipment) } let!(:adjustment2) { + create(:adjustment, originator_type: "Spree::PaymentMethod", eligible: true, order: order) + } + let!(:adjustment3) { create(:adjustment, originator_type: "Spree::PaymentMethod", eligible: false, order: order) } - let!(:adjustment3) { create(:adjustment, originator_type: "EnterpriseFee", order: order) } + let!(:adjustment4) { create(:adjustment, originator_type: "EnterpriseFee", order: order) } + let!(:adjustment5) { create(:adjustment, originator: nil, adjustable: order, order: order) } - it "loads all eligible adjustments" do + it "displays eligible adjustments" do spree_get :index, order_id: order.number - expect(assigns(:collection)).to include adjustment1, adjustment3 - expect(assigns(:collection)).to_not include adjustment2 + expect(assigns(:collection)).to include adjustment1, adjustment2 + expect(assigns(:collection)).to_not include adjustment3 + end + + it "displays admin adjustments" do + spree_get :index, order_id: order.number + + expect(assigns(:collection)).to include adjustment5 + end + + it "does not display enterprise fee adjustments" do + spree_get :index, order_id: order.number + + expect(assigns(:collection)).to_not include adjustment4 end end