Introduced StockTaking. TODO: Dry up the stockit/stock_takings/deliveries controllers/views!
This commit is contained in:
parent
2bb4cdb9d6
commit
951d19db6a
30 changed files with 436 additions and 55 deletions
|
|
@ -82,10 +82,10 @@ class DeliveriesController < ApplicationController
|
|||
page.insert_html :top, 'stock_changes', :partial => 'stock_change',
|
||||
:locals => {:stock_change => article.stock_changes.build}
|
||||
|
||||
page.replace_html 'new_stock_article', :partial => 'new_stock_article',
|
||||
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
|
||||
:locals => {:stock_article => @supplier.stock_articles.build}
|
||||
else
|
||||
page.replace_html 'new_stock_article', :partial => 'new_stock_article',
|
||||
page.replace_html 'new_stock_article', :partial => 'stock_article_form',
|
||||
:locals => {:stock_article => article}
|
||||
end
|
||||
end
|
||||
|
|
@ -100,13 +100,6 @@ class DeliveriesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def auto_complete_for_article_name
|
||||
@articles = @supplier.articles.without_deleted.find(:all,
|
||||
:conditions => [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ],
|
||||
:limit => 8)
|
||||
render :partial => 'shared/auto_complete_articles'
|
||||
end
|
||||
|
||||
def fill_new_stock_article_form
|
||||
article = Article.find(params[:article_id])
|
||||
@supplier = article.supplier
|
||||
|
|
@ -114,7 +107,7 @@ class DeliveriesController < ApplicationController
|
|||
article.attributes.reject { |attr| attr == ('id' || 'type')}
|
||||
)
|
||||
|
||||
render :partial => 'new_stock_article', :locals => {:stock_article => stock_article}
|
||||
render :partial => 'stock_article_form', :locals => {:stock_article => stock_article}
|
||||
end
|
||||
|
||||
def in_place_edit_for_stock_quantity
|
||||
|
|
|
|||
112
app/controllers/stock_takings_controller.rb
Normal file
112
app/controllers/stock_takings_controller.rb
Normal file
|
|
@ -0,0 +1,112 @@
|
|||
class StockTakingsController < ApplicationController
|
||||
|
||||
def index
|
||||
@stock_takings = StockTaking.find(:all)
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @stock_takings }
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@stock_taking = StockTaking.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @stock_taking }
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@stock_taking = StockTaking.new
|
||||
StockArticle.without_deleted.each { |a| @stock_taking.stock_changes.build(:stock_article => a) }
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @stock_taking }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def edit
|
||||
@stock_taking = StockTaking.find(params[:id])
|
||||
end
|
||||
|
||||
def create
|
||||
@stock_taking = StockTaking.new(params[:stock_taking])
|
||||
|
||||
respond_to do |format|
|
||||
if @stock_taking.save
|
||||
flash[:notice] = 'StockTaking was successfully created.'
|
||||
format.html { redirect_to(@stock_taking) }
|
||||
format.xml { render :xml => @stock_taking, :status => :created, :location => @stock_taking }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @stock_taking.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@stock_taking = StockTaking.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @stock_taking.update_attributes(params[:stock_taking])
|
||||
flash[:notice] = 'StockTaking was successfully updated.'
|
||||
format.html { redirect_to(@stock_taking) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @stock_taking.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@stock_taking = StockTaking.find(params[:id])
|
||||
@stock_taking.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(stock_takings_url) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
|
||||
end
|
||||
|
|
@ -8,16 +8,13 @@ class StockitController < ApplicationController
|
|||
end
|
||||
|
||||
def new
|
||||
@supplier = Supplier.find(params[:supplier_id])
|
||||
@stock_article = @supplier.stock_articles.build(:tax => 7.0)
|
||||
rescue
|
||||
flash[:error] = "Es wurde kein gültiger Lieferant ausgewählt."
|
||||
redirect_to stock_articles_path
|
||||
@stock_article = StockArticle.new
|
||||
end
|
||||
|
||||
def create
|
||||
@stock_article = StockArticle.new(params[:stock_article])
|
||||
if @stock_article.save
|
||||
flash[:notice] = "Lagerartikel wurde gespeichert."
|
||||
redirect_to stock_articles_path
|
||||
else
|
||||
render :action => 'new'
|
||||
|
|
@ -31,6 +28,7 @@ class StockitController < ApplicationController
|
|||
def update
|
||||
@stock_article = StockArticle.find(params[:id])
|
||||
if @stock_article.update_attributes(params[:stock_article])
|
||||
flash[:notice] = "Lagerartikel wurde gespeichert."
|
||||
redirect_to stock_articles_path
|
||||
else
|
||||
render :action => 'edit'
|
||||
|
|
@ -46,10 +44,14 @@ class StockitController < ApplicationController
|
|||
end
|
||||
|
||||
def auto_complete_for_article_name
|
||||
@supplier = Supplier.find(params[:supplier_id])
|
||||
@articles = @supplier.articles.without_deleted.find(:all,
|
||||
:conditions => [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ],
|
||||
:limit => 8)
|
||||
conditions = [ "LOWER(articles.name) LIKE ?", '%' + params[:article][:name].downcase + '%' ]
|
||||
|
||||
if params[:supplier_id]
|
||||
@supplier = Supplier.find(params[:supplier_id])
|
||||
@articles = @supplier.articles.without_deleted.all(:conditions => conditions, :limit => 8)
|
||||
else
|
||||
@articles = Article.without_deleted.not_in_stock.all(:conditions => conditions, :limit => 8)
|
||||
end
|
||||
render :partial => 'shared/auto_complete_articles'
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue