i18n cleanup (affects foodcoops#137)

This commit is contained in:
wvengen 2013-12-06 22:43:36 +01:00
parent 043607f20d
commit a475a27f79
3 changed files with 18 additions and 22 deletions

View file

@ -14,10 +14,14 @@ class StockArticle < Article
# Check for unclosed orders and substract its ordered quantity
def quantity_available
quantity - OrderArticle.where(article_id: id).
quantity - quantity_ordered
end
def quantity_ordered
OrderArticle.where(article_id: id).
joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order)
end
def quantity_history
stock_changes.reorder('stock_changes.created_at ASC').map{|s| s.quantity}.cumulative_sum
end