Class: Spree::Admin::StockTransfersController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/spree/admin/stock_transfers_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/controllers/spree/admin/stock_transfers_controller.rb', line 21

def create
  if params[:variant].nil?
    flash[:error] = Spree.t('stock_transfer.errors.must_have_variant')
    render :new
  else
    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
end

#indexObject



6
7
8
9
10
11
12
13
# File 'app/controllers/spree/admin/stock_transfers_controller.rb', line 6

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

#newObject



19
# File 'app/controllers/spree/admin/stock_transfers_controller.rb', line 19

def new; end

#showObject



15
16
17
# File 'app/controllers/spree/admin/stock_transfers_controller.rb', line 15

def show
  @stock_transfer = StockTransfer.find_by!(number: params[:id])
end