Sha256: 7a8af72fca5d3f937b81947214e211120a6eeaf5f8caba32813ce9b6f7547feb

Contents?: true

Size: 1.55 KB

Versions: 32

Compression:

Stored size: 1.55 KB

Contents

module Spree
  module Admin
    class StockTransfersController < Admin::BaseController
      before_action :load_stock_locations, only: :index

      def index
        @q = StockTransfer.ransack(params[:q])

        @stock_transfers = @q.result.
                             includes(stock_movements: { stock_item: :stock_location }).
                             order(created_at: :desc).
                             page(params[:page])
      end

      def show
        @stock_transfer = StockTransfer.friendly.find(params[:id])
      end

      def new; end

      def create
        variants = Hash.new(0)
        params[:variant].each_with_index do |variant_id, i|
          variants[variant_id] += params[:quantity][i].to_i
        end

        stock_transfer = StockTransfer.create(reference: params[:reference])
        stock_transfer.transfer(source_location,
                                destination_location,
                                variants)

        flash[:success] = Spree.t(:stock_successfully_transferred)
        redirect_to admin_stock_transfer_path(stock_transfer)
      end

      private
      def load_stock_locations
        @stock_locations = Spree::StockLocation.active.order_default
      end

      def source_location
        @source_location ||= params.has_key?(:transfer_receive_stock) ? nil :
                               StockLocation.find(params[:transfer_source_location_id])
      end

      def destination_location
        @destination_location ||= StockLocation.find(params[:transfer_destination_location_id])
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
spree_backend-3.2.9 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.14 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.8 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.13 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.7 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.12 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.6 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.11 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.10 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.5 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.9 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.4 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.8 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.7 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.3 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.2 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.6 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.1.5 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.1 app/controllers/spree/admin/stock_transfers_controller.rb
spree_backend-3.2.0 app/controllers/spree/admin/stock_transfers_controller.rb