Rename and comment new functions for fixing stock ordering

This commit is contained in:
Julius 2013-03-15 08:50:55 +01:00
parent 8d0761a6c8
commit 6aa0e0b736
2 changed files with 6 additions and 3 deletions

View File

@ -49,7 +49,8 @@ class Article < ActiveRecord::Base
end
memoize :in_open_order
def ordered?(order)
# Returns true if the article has been ordered in the given order at least once
def ordered_in_order?(order)
order.order_articles.where(article_id: id).where('quantity > 0').one?
end

View File

@ -38,9 +38,11 @@ class Order < ActiveRecord::Base
def articles_for_ordering
if stockit?
# make sure to include those articles which are no longer available
# but which have already been ordered in this stock order
StockArticle.available.all(:include => :article_category,
:order => 'article_categories.name, articles.name').reject{ |a|
a.quantity_available <= 0 and not a.ordered?(self)
a.quantity_available <= 0 and not a.ordered_in_order?(self)
}.group_by { |a| a.article_category.name }
else
supplier.articles.available.all.group_by { |a| a.article_category.name }