/backend/app/controllers/spree/admin/stock_transfers_controller.rb

https://github.com/chienyuan/spree · Ruby · 53 lines · 42 code · 11 blank · 0 comment · 0 complexity · c59aabdb87dc97230d483dde260655e7 MD5 · raw file

  1. module Spree
  2. module Admin
  3. class StockTransfersController < Admin::BaseController
  4. before_filter :load_stock_locations, :only => :index
  5. def index
  6. @q = StockTransfer.ransack(params[:q])
  7. @stock_transfers = @q.result
  8. .includes(:stock_movements => { :stock_item => :stock_location })
  9. .order('created_at DESC')
  10. .page(params[:page])
  11. end
  12. def show
  13. @stock_transfer = StockTransfer.find_by_param(params[:id])
  14. end
  15. def new
  16. end
  17. def create
  18. variants = Hash.new(0)
  19. params[:variant].each_with_index do |variant_id, i|
  20. variants[variant_id] += params[:quantity][i].to_i
  21. end
  22. stock_transfer = StockTransfer.create(:reference => params[:reference])
  23. stock_transfer.transfer(source_location,
  24. destination_location,
  25. variants)
  26. flash[:success] = Spree.t(:stock_successfully_transferred)
  27. redirect_to admin_stock_transfer_path(stock_transfer)
  28. end
  29. private
  30. def load_stock_locations
  31. @stock_locations = Spree::StockLocation.active.order('name ASC')
  32. end
  33. def source_location
  34. @source_location ||= params.has_key?(:transfer_receive_stock) ? nil :
  35. StockLocation.find(params[:transfer_source_location_id])
  36. end
  37. def destination_location
  38. @destination_location ||= StockLocation.find(params[:transfer_destination_location_id])
  39. end
  40. end
  41. end
  42. end