Improve stock_article_selections

This commit is contained in:
Julius 2013-01-28 20:46:35 +01:00
parent 524819b86f
commit 396a47b6af
10 changed files with 104 additions and 30 deletions

View file

@ -22,6 +22,11 @@ class StockArticle < Article
def self.stock_value
available.collect { |a| a.quantity * a.gross_price }.sum
end
def self.elements_for_index
StockArticle.includes(:supplier, :article_category).
order('suppliers.name, article_categories.name, articles.name')
end
protected

View file

@ -13,6 +13,18 @@ class StockArticleSelection < ActiveRecord::Base
all_articles = stock_article_ids
end
def deletable_count
stock_articles.select { |a| a.quantity_available<=0 }.length
end
def nondeletable_count
stock_articles.select { |a| a.quantity_available>0 }.length
end
def deleted_count
stock_articles.only_deleted.count
end
protected
def include_stock_articles