Class: StockTakingsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/stock_takings_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

current

Instance Method Details

#add_stock_articleObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/stock_takings_controller.rb', line 31

def add_stock_article
  article = StockArticle.new(params[:stock_article])
  render :update do |page|
    if article.save
      page.insert_html :top, 'stock_changes', :partial => 'stock_change',
        :locals => {:stock_change => article.stock_changes.build}

      page.replace_html 'new_stock_article', :partial => 'stock_article_form',
        :locals => {:stock_article => StockArticle.new}
    else
      page.replace_html 'new_stock_article', :partial => 'stock_article_form',
        :locals => {:stock_article => article}
    end
  end
end

#createObject


13
14
15
# File 'app/controllers/stock_takings_controller.rb', line 13

def create
  create!(:notice => I18n.t('stock_takings.create.notice'))
end

#drop_stock_changeObject


47
48
49
50
51
52
53
54
# File 'app/controllers/stock_takings_controller.rb', line 47

def drop_stock_change
  stock_change = StockChange.find(params[:stock_change_id])
  stock_change.destroy

  render :update do |page|
    page.visual_effect :DropOut, "stock_change_#{stock_change.id}"
  end
end

#fill_new_stock_article_formObject


21
22
23
24
25
26
27
28
29
# File 'app/controllers/stock_takings_controller.rb', line 21

def fill_new_stock_article_form
  article = Article.find(params[:article_id])
  supplier = article.supplier
  stock_article = supplier.stock_articles.build(
    article.attributes.reject { |attr| attr == ('id' || 'type')}
  )

  render :partial => 'stock_article_form', :locals => {:stock_article => stock_article}
end

#indexObject


4
5
6
# File 'app/controllers/stock_takings_controller.rb', line 4

def index
  @stock_takings = StockTaking.order('date DESC').page(params[:page]).per(@per_page)
end

#newObject


8
9
10
11
# File 'app/controllers/stock_takings_controller.rb', line 8

def new
  @stock_taking = StockTaking.new
  StockArticle.undeleted.each { |a| @stock_taking.stock_changes.build(:stock_article => a) }
end

#updateObject


17
18
19
# File 'app/controllers/stock_takings_controller.rb', line 17

def update
  update!(:notice => I18n.t('stock_takings.update.notice'))
end