From 9cc98b4662235293c1aaa5ae6168397a4a5849f8 Mon Sep 17 00:00:00 2001 From: Benjamin Meichsner Date: Sun, 17 Mar 2013 15:12:14 +0100 Subject: [PATCH] Added some more eager loading for balancing view. --- .../finance/balancing_controller.rb | 2 +- app/models/order.rb | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/app/controllers/finance/balancing_controller.rb b/app/controllers/finance/balancing_controller.rb index 71ce19ed..c6e1b108 100644 --- a/app/controllers/finance/balancing_controller.rb +++ b/app/controllers/finance/balancing_controller.rb @@ -10,7 +10,7 @@ class Finance::BalancingController < Finance::BaseController flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed? @comments = @order.comments - @articles = @order.order_articles.ordered.includes(:order, :article_price, + @articles = @order.order_articles.ordered.includes(:article, :article_price, group_order_articles: {group_order: :ordergroup}) sort_param = params['sort'] || 'name' diff --git a/app/models/order.rb b/app/models/order.rb index 480df14a..7cc5c4bd 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -113,25 +113,25 @@ class Order < ActiveRecord::Base def sum(type = :gross) total = 0 if type == :net || type == :gross || type == :fc - for oa in order_articles.ordered.all(:include => [:article,:article_price]) + for oa in order_articles.ordered.includes(:article, :article_price) quantity = oa.units_to_order * oa.price.unit_quantity case type - when :net - total += quantity * oa.price.price - when :gross - total += quantity * oa.price.gross_price - when :fc - total += quantity * oa.price.fc_price + when :net + total += quantity * oa.price.price + when :gross + total += quantity * oa.price.gross_price + when :fc + total += quantity * oa.price.fc_price end end elsif type == :groups || type == :groups_without_markup - for go in group_orders.all(:include => :group_order_articles) - for goa in go.group_order_articles.all(:include => [:order_article]) + for go in group_orders.includes(group_order_articles: {order_article: [:article, :article_price]}) + for goa in go.group_order_articles case type - when :groups - total += goa.result * goa.order_article.price.fc_price - when :groups_without_markup - total += goa.result * goa.order_article.price.gross_price + when :groups + total += goa.result * goa.order_article.price.fc_price + when :groups_without_markup + total += goa.result * goa.order_article.price.gross_price end end end