Merge pull request #173 from foodcoop-adam/keep-member-order-on-orderarticle-deletion
Keep member order on orderarticle deletion
This commit is contained in:
commit
857eb64a45
3 changed files with 69 additions and 2 deletions
|
|
@ -65,7 +65,13 @@ class Finance::GroupOrderArticlesController < ApplicationController
|
|||
|
||||
def destroy
|
||||
group_order_article = GroupOrderArticle.find(params[:id])
|
||||
group_order_article.destroy
|
||||
# only destroy if quantity and tolerance was zero already, so that we don't
|
||||
# lose what the user ordered, if any
|
||||
if group_order_article.quantity > 0 or group_order_article.tolerance >0
|
||||
group_order_article.update_attribute(:result, 0)
|
||||
else
|
||||
group_order_article.destroy
|
||||
end
|
||||
update_summaries(group_order_article)
|
||||
@order_article = group_order_article.order_article
|
||||
|
||||
|
|
|
|||
|
|
@ -42,6 +42,14 @@ class Finance::OrderArticlesController < ApplicationController
|
|||
|
||||
def destroy
|
||||
@order_article = OrderArticle.find(params[:id])
|
||||
@order_article.destroy
|
||||
# only destroy if there are no associated GroupOrders; if we would, the requested
|
||||
# quantity and tolerance would be gone. Instead of destroying, we set all result
|
||||
# quantities to zero.
|
||||
if @order_article.group_order_articles.count == 0
|
||||
@order_article.destroy
|
||||
else
|
||||
@order_article.group_order_articles.each { |goa| goa.update_attribute(:result, 0) }
|
||||
@order_article.update_results!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue