Fixed missing group_order_article in group_order show.
Also add eager loading for associated objects.
This commit is contained in:
parent
0fcd5abb3a
commit
9919183cb0
4 changed files with 22 additions and 17 deletions
|
@ -25,4 +25,15 @@ module GroupOrdersHelper
|
|||
'ignored'
|
||||
end
|
||||
end
|
||||
|
||||
def get_order_results(order_article, group_order_id)
|
||||
goa = order_article.group_order_articles.detect { |goa| goa.group_order_id == group_order_id }
|
||||
quantity, tolerance, result, sub_total = if goa.present?
|
||||
[goa.quantity, goa.tolerance, goa.result, goa.total_price(order_article)]
|
||||
else
|
||||
[0, 0, 0, 0]
|
||||
end
|
||||
|
||||
{group_order_article: goa, quantity: quantity, tolerance: tolerance, result: result, sub_total: sub_total}
|
||||
end
|
||||
end
|
|
@ -166,7 +166,7 @@ class GroupOrderArticle < ActiveRecord::Base
|
|||
# Until the order is finished this will be the maximum price or
|
||||
# the minimum price depending on configuration. When the order is finished it
|
||||
# will be the value depending of the article results.
|
||||
def total_price
|
||||
def total_price(order_article = self.order_article)
|
||||
unless order_article.order.finished?
|
||||
if FoodsoftConfig[:tolerance_is_costly]
|
||||
order_article.article.fc_price * (quantity + tolerance)
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
# encoding: utf-8
|
||||
#
|
||||
class Order < ActiveRecord::Base
|
||||
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
|
||||
|
||||
# Associations
|
||||
has_many :order_articles, :dependent => :destroy
|
||||
|
@ -86,11 +85,11 @@ class Order < ActiveRecord::Base
|
|||
# The array has the following form:
|
||||
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
||||
def articles_grouped_by_category
|
||||
order_articles.includes(:article, :article_price).order('articles.name').
|
||||
order_articles.includes([:article_price, :group_order_articles, :article => :article_category]).
|
||||
order('articles.name').
|
||||
group_by { |a| a.article.article_category.name }.
|
||||
sort { |a, b| a[0] <=> b[0] }
|
||||
end
|
||||
memoize :articles_grouped_by_category
|
||||
|
||||
def articles_sort_by_category
|
||||
order_articles.all(:include => [:article], :order => 'articles.name').sort do |a,b|
|
||||
|
|
|
@ -54,26 +54,21 @@
|
|||
= category_name
|
||||
%i.icon-tag
|
||||
%td{colspan: "9"}
|
||||
- for oa in order_articles
|
||||
- order_articles.each do |oa|
|
||||
- # get the order-results for the ordergroup
|
||||
- goa = oa.group_order_articles.find_by_group_order_id(@group_order.id)
|
||||
- quantity = goa.quantity
|
||||
- tolerance = goa.tolerance
|
||||
- result = goa.result
|
||||
- sub_total = goa.total_price
|
||||
- total += sub_total
|
||||
%tr{class: cycle('even', 'odd', name: 'articles') + " " + order_article_class_name(quantity, tolerance, result)}
|
||||
- r = get_order_results(oa, @group_order.id)
|
||||
%tr{class: cycle('even', 'odd', name: 'articles') + " " + order_article_class_name(r[:quantity], r[:tolerance], r[:result])}
|
||||
%td{style: "width:40%"}
|
||||
=h oa.article.name
|
||||
= oa.article.name
|
||||
- unless oa.article.note.blank?
|
||||
= image_tag("lamp_grey.png", {alt: "Notiz anzeigen", size: "15x16", border: "0", onmouseover: "$('note_#{oa.id}').show();", onmouseout: "$('note_#{oa.id}').hide();"})
|
||||
%td= "#{oa.price.unit_quantity} x #{oa.article.unit}"
|
||||
%td= number_to_currency(oa.price.fc_price)
|
||||
%td
|
||||
= quantity
|
||||
= "+ #{tolerance}" if oa.price.unit_quantity > 1
|
||||
%td= result > 0 ? result : "0"
|
||||
%td= number_to_currency(sub_total)
|
||||
= r[:quantity]
|
||||
= "+ #{r[:tolerance]}" if oa.price.unit_quantity > 1
|
||||
%td= r[:result] > 0 ? r[:result] : "0"
|
||||
%td= number_to_currency(r[:sub_total])
|
||||
- unless oa.article.note.blank?
|
||||
%tr{id: "note_#{oa.id}", class: "note even", style: "display:none"}
|
||||
%td{colspan: "6"}=h oa.article.note
|
||||
|
|
Loading…
Reference in a new issue