diff --git a/app/models/group_order.rb b/app/models/group_order.rb index f12ab7c3..3a93c011 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -76,7 +76,7 @@ class GroupOrder < ActiveRecord::Base # Updates the "price" attribute. def update_price! - total = group_order_articles.includes(:order_article => :article).all.map(&:total_price).sum + total = group_order_articles.includes(:order_article => [:article, :article_price]).to_a.sum(&:total_price) update_attribute(:price, total) end diff --git a/app/models/order.rb b/app/models/order.rb index 31276a48..2d9fe7b1 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -164,10 +164,10 @@ class Order < ActiveRecord::Base end # Update GroupOrder prices - group_orders.each { |go| go.update_price! } + group_orders.each(&:update_price!) # Stats - ordergroups.each { |o| o.update_stats! } + ordergroups.each(&:update_stats!) # Notifications UserNotifier.delay.finished_order(self.id) diff --git a/app/models/order_article.rb b/app/models/order_article.rb index 102cfa01..a6b13a27 100644 --- a/app/models/order_article.rb +++ b/app/models/order_article.rb @@ -137,7 +137,6 @@ class OrderArticle < ActiveRecord::Base def update_ordergroup_prices group_order_articles.each { |goa| goa.group_order.update_price! } end - handle_asynchronously :update_ordergroup_prices end