Merge pull request #150 from foodcoop-rostock/stock_article_quantity_history

Show StockChanges index
This commit is contained in:
wvengen 2013-07-13 03:16:31 -07:00
commit 126f7e7459
10 changed files with 68 additions and 1 deletions

View file

@ -17,6 +17,10 @@ class StockArticle < Article
quantity - 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
def self.stock_value
available.collect { |a| a.quantity * a.gross_price }.sum

View file

@ -1,6 +1,7 @@
class StockChange < ActiveRecord::Base
belongs_to :delivery
belongs_to :order
belongs_to :stock_taking
belongs_to :stock_article
validates_presence_of :stock_article_id, :quantity