2012-06-21 17:19:00 +02:00
|
|
|
class Finance::OrderArticlesController < ApplicationController
|
|
|
|
|
|
|
|
before_filter :authenticate_finance
|
|
|
|
|
2012-07-27 18:03:46 +02:00
|
|
|
layout false # We only use this controller to serve js snippets, no need for layout rendering
|
2012-06-21 17:19:00 +02:00
|
|
|
|
|
|
|
def new
|
|
|
|
@order = Order.find(params[:order_id])
|
|
|
|
@order_article = @order.order_articles.build
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
@order = Order.find(params[:order_id])
|
2013-06-24 13:32:07 +02:00
|
|
|
# The article may with zero units ordered - in that case find and set amount to nonzero.
|
|
|
|
# If order_article is ordered and a new order_article is created, an error message will be
|
|
|
|
# given mentioning that the article already exists, which is desired.
|
|
|
|
@order_article = @order.order_articles.where(:article_id => params[:order_article][:article_id]).first
|
|
|
|
if @order_article and @order_article.units_to_order == 0
|
|
|
|
@order_article.units_to_order = 1
|
|
|
|
else
|
|
|
|
@order_article = @order.order_articles.build(params[:order_article])
|
|
|
|
end
|
2012-06-21 17:19:00 +02:00
|
|
|
unless @order_article.save
|
|
|
|
render action: :new
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@order = Order.find(params[:order_id])
|
|
|
|
@order_article = OrderArticle.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@order = Order.find(params[:order_id])
|
|
|
|
@order_article = OrderArticle.find(params[:id])
|
|
|
|
begin
|
2013-03-17 18:33:04 +01:00
|
|
|
@order_article.update_article_and_price!(params[:order_article], params[:article], params[:article_price])
|
2012-06-21 17:19:00 +02:00
|
|
|
rescue
|
|
|
|
render action: :edit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@order_article = OrderArticle.find(params[:id])
|
|
|
|
@order_article.destroy
|
|
|
|
end
|
|
|
|
end
|