Class: GroupOrderArticlesController
Instance Method Summary
collapse
current
Methods included from PathHelper
#finance_group_transactions_path
Instance Method Details
#create ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'app/controllers/group_order_articles_controller.rb', line 12
def create
@group_order_article = GroupOrderArticle.new(params[:group_order_article])
@order_article = @group_order_article.order_article
goa = GroupOrderArticle.where(group_order_id: @group_order_article.group_order_id,
order_article_id: @order_article.id).first
if goa && goa.update(params[:group_order_article])
@group_order_article = goa
update_summaries(@group_order_article)
render :create
elsif @group_order_article.save
update_summaries(@group_order_article)
render :create
else render :new
end
end
|
#destroy ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
|
# File 'app/controllers/group_order_articles_controller.rb', line 49
def destroy
if @group_order_article.quantity > 0 || @group_order_article.tolerance > 0
@group_order_article.update_attribute(:result, 0)
else
@group_order_article.destroy
end
update_summaries(@group_order_article)
render :update
end
|
#find_group_order_article ⇒ Object
71
72
73
|
# File 'app/controllers/group_order_articles_controller.rb', line 71
def find_group_order_article
@group_order_article = GroupOrderArticle.find(params[:id])
end
|
#new ⇒ Object
7
8
9
10
|
# File 'app/controllers/group_order_articles_controller.rb', line 7
def new
@order_article = OrderArticle.find(params[:order_article_id])
@group_order_article = GroupOrderArticle.new(order_article: @order_article)
end
|
#update ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'app/controllers/group_order_articles_controller.rb', line 37
def update
if params[:delta]
@group_order_article.update_attribute :result, [@group_order_article.result + params[:delta].to_f, 0].max
else
@group_order_article.update(params[:group_order_article])
end
update_summaries(@group_order_article)
render :update
end
|
#update_summaries(group_order_article) ⇒ Object
64
65
66
67
68
69
|
# File 'app/controllers/group_order_articles_controller.rb', line 64
def update_summaries(group_order_article)
group_order_article.group_order.update_price!
group_order_article.order_article.update_results! if group_order_article.order_article.article.is_a?(StockArticle)
end
|