Added some more eager loading for balancing view.
This commit is contained in:
parent
07581b7ecf
commit
9cc98b4662
2 changed files with 14 additions and 14 deletions
|
@ -10,7 +10,7 @@ class Finance::BalancingController < Finance::BaseController
|
||||||
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
flash.now.alert = "Achtung, Bestellung wurde schon abgerechnet" if @order.closed?
|
||||||
@comments = @order.comments
|
@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})
|
group_order_articles: {group_order: :ordergroup})
|
||||||
|
|
||||||
sort_param = params['sort'] || 'name'
|
sort_param = params['sort'] || 'name'
|
||||||
|
|
|
@ -113,25 +113,25 @@ class Order < ActiveRecord::Base
|
||||||
def sum(type = :gross)
|
def sum(type = :gross)
|
||||||
total = 0
|
total = 0
|
||||||
if type == :net || type == :gross || type == :fc
|
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
|
quantity = oa.units_to_order * oa.price.unit_quantity
|
||||||
case type
|
case type
|
||||||
when :net
|
when :net
|
||||||
total += quantity * oa.price.price
|
total += quantity * oa.price.price
|
||||||
when :gross
|
when :gross
|
||||||
total += quantity * oa.price.gross_price
|
total += quantity * oa.price.gross_price
|
||||||
when :fc
|
when :fc
|
||||||
total += quantity * oa.price.fc_price
|
total += quantity * oa.price.fc_price
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elsif type == :groups || type == :groups_without_markup
|
elsif type == :groups || type == :groups_without_markup
|
||||||
for go in group_orders.all(:include => :group_order_articles)
|
for go in group_orders.includes(group_order_articles: {order_article: [:article, :article_price]})
|
||||||
for goa in go.group_order_articles.all(:include => [:order_article])
|
for goa in go.group_order_articles
|
||||||
case type
|
case type
|
||||||
when :groups
|
when :groups
|
||||||
total += goa.result * goa.order_article.price.fc_price
|
total += goa.result * goa.order_article.price.fc_price
|
||||||
when :groups_without_markup
|
when :groups_without_markup
|
||||||
total += goa.result * goa.order_article.price.gross_price
|
total += goa.result * goa.order_article.price.gross_price
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue