From 1298af83773114dc8c5db92db989ce445ac3f3ee Mon Sep 17 00:00:00 2001 From: benni Date: Sun, 16 Dec 2012 21:46:24 +0100 Subject: [PATCH] Small improvement for update price. Removed delayed job. Attention, every delayed job has to know its Foodcoop scope. Otherwise every task will be executed in the default database. See email delivery. --- app/models/group_order.rb | 2 +- app/models/order.rb | 4 ++-- app/models/order_article.rb | 1 - 3 files changed, 3 insertions(+), 4 deletions(-) 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