fix adding article balancing failing with 'already taken' (closes foodcoops/foodsoft#125)
This commit is contained in:
parent
cab6ada8b8
commit
7dbe1363ed
1 changed files with 9 additions and 1 deletions
|
@ -11,7 +11,15 @@ class Finance::OrderArticlesController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@order = Order.find(params[:order_id])
|
@order = Order.find(params[:order_id])
|
||||||
@order_article = @order.order_articles.build(params[:order_article])
|
# 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
|
||||||
unless @order_article.save
|
unless @order_article.save
|
||||||
render action: :new
|
render action: :new
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue