Minor speed improvements for group order load.
This commit is contained in:
parent
2a66d37c3a
commit
3ab3ff2bc4
2 changed files with 20 additions and 16 deletions
|
@ -38,20 +38,23 @@ class GroupOrder < ActiveRecord::Base
|
||||||
|
|
||||||
# load prices and other stuff....
|
# load prices and other stuff....
|
||||||
data[:order_articles] = {}
|
data[:order_articles] = {}
|
||||||
order.order_articles.each do |order_article|
|
#order.order_articles.each do |order_article|
|
||||||
data[:order_articles][order_article.id] = {
|
order.articles_grouped_by_category.each do |article_category, order_articles|
|
||||||
:price => order_article.article.fc_price,
|
order_articles.each do |order_article|
|
||||||
:unit => order_article.article.unit_quantity,
|
data[:order_articles][order_article.id] = {
|
||||||
:quantity => (new_record? ? 0 : goas[order_article.id][:quantity]),
|
:price => order_article.article.fc_price,
|
||||||
:others_quantity => order_article.quantity - (new_record? ? 0 : goas[order_article.id][:quantity]),
|
:unit => order_article.article.unit_quantity,
|
||||||
:used_quantity => (new_record? ? 0 : goas[order_article.id][:quantity_result]),
|
:quantity => (new_record? ? 0 : goas[order_article.id][:quantity]),
|
||||||
:tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance]),
|
:others_quantity => order_article.quantity - (new_record? ? 0 : goas[order_article.id][:quantity]),
|
||||||
:others_tolerance => order_article.tolerance - (new_record? ? 0 : goas[order_article.id][:tolerance]),
|
:used_quantity => (new_record? ? 0 : goas[order_article.id][:quantity_result]),
|
||||||
:used_tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance_result]),
|
:tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance]),
|
||||||
:total_price => (new_record? ? 0 : goas[order_article.id][:total_price]),
|
:others_tolerance => order_article.tolerance - (new_record? ? 0 : goas[order_article.id][:tolerance]),
|
||||||
:missing_units => order_article.missing_units,
|
:used_tolerance => (new_record? ? 0 : goas[order_article.id][:tolerance_result]),
|
||||||
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
|
:total_price => (new_record? ? 0 : goas[order_article.id][:total_price]),
|
||||||
}
|
:missing_units => order_article.missing_units,
|
||||||
|
:quantity_available => (order.stockit? ? order_article.article.quantity_available : 0)
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
data
|
data
|
||||||
|
|
|
@ -85,9 +85,10 @@ class Order < ActiveRecord::Base
|
||||||
# The array has the following form:
|
# The array has the following form:
|
||||||
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
# e.g: [["drugs",[teethpaste, toiletpaper]], ["fruits" => [apple, banana, lemon]]]
|
||||||
def articles_grouped_by_category
|
def articles_grouped_by_category
|
||||||
order_articles.includes([:article_price, :group_order_articles, :article => :article_category]).
|
@articles_grouped_by_category ||= order_articles.
|
||||||
|
includes([:article_price, :group_order_articles, :article => :article_category]).
|
||||||
order('articles.name').
|
order('articles.name').
|
||||||
group_by { |a| a.article.article_category.name }.
|
group_by { |a| a.article.article_category.name }.
|
||||||
sort { |a, b| a[0] <=> b[0] }
|
sort { |a, b| a[0] <=> b[0] }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue