Sha256: 1c7e6645e3ea93c30901444f5fc25fd8644d270591f41ef114982be2739555d2

Contents?: true

Size: 1.17 KB

Versions: 21

Compression:

Stored size: 1.17 KB

Contents

module Spree
  module Admin
    class AdjustmentsController < ResourceController
      belongs_to 'spree/order', find_by: :number

      create.after :update_totals
      destroy.after :update_totals
      update.after :update_totals

      skip_before_action :load_resource, only: [:toggle_state, :edit, :update, :destroy]

      before_action :find_adjustment, only: [:destroy, :edit, :update]

      helper_method :reasons_for

      def index
        @adjustments = @order.all_adjustments.order("created_at ASC")
      end

      private

      def find_adjustment
        # Need to assign to @object here to keep ResourceController happy
        @adjustment = @object = parent.all_adjustments.find(params[:id])
      end

      def update_totals
        @order.reload.update!
      end

      # Override method used to create a new instance to correctly
      # associate adjustment with order
      def build_resource
        parent.adjustments.build(order: parent)
      end

      def reasons_for(_adjustment)
        [
          AdjustmentReason.active.to_a,
          @adjustment.adjustment_reason
        ].flatten.compact.uniq.sort_by { |r| r.name.downcase }
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
solidus_backend-2.1.1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.0.3 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.4.2 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.3.2 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.0.2 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.4.1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.1.0 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.1.0.rc1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.0.1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.1.0.beta1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.0.0 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.4.0 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.0.0.rc1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.4.0.rc1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-2.0.0.beta1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.4.0.beta1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.3.1 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.3.0 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.3.0.rc2 app/controllers/spree/admin/adjustments_controller.rb
solidus_backend-1.3.0.rc1 app/controllers/spree/admin/adjustments_controller.rb