Performance improvement for stockit view.
This commit is contained in:
parent
9ac747e9f3
commit
ef2ce98e46
2 changed files with 4 additions and 10 deletions
|
@ -1,7 +1,7 @@
|
||||||
class StockitController < ApplicationController
|
class StockitController < ApplicationController
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@stock_articles = StockArticle.joins(:supplier, :article_category).
|
@stock_articles = StockArticle.includes(:supplier, :article_category).
|
||||||
order('suppliers.name, article_categories.name, articles.name')
|
order('suppliers.name, article_categories.name, articles.name')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -14,15 +14,9 @@ class StockArticle < Article
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check for unclosed orders and substract its ordered quantity
|
# Check for unclosed orders and substract its ordered quantity
|
||||||
def quantity_available(exclude_order = nil)
|
def quantity_available
|
||||||
available = quantity
|
quantity - OrderArticle.where(article_id: id).
|
||||||
for order in Order.stockit.all(:conditions => "state = 'open' OR state = 'finished'")
|
joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order)
|
||||||
unless order == exclude_order
|
|
||||||
order_article = order.order_articles.first(:conditions => {:article_id => id})
|
|
||||||
available -= order_article.units_to_order if order_article
|
|
||||||
end
|
|
||||||
end
|
|
||||||
available
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.stock_value
|
def self.stock_value
|
||||||
|
|
Loading…
Reference in a new issue