Rename and comment new functions for fixing stock ordering
This commit is contained in:
parent
8d0761a6c8
commit
6aa0e0b736
2 changed files with 6 additions and 3 deletions
|
@ -49,7 +49,8 @@ class Article < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
memoize :in_open_order
|
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?
|
order.order_articles.where(article_id: id).where('quantity > 0').one?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,9 +38,11 @@ class Order < ActiveRecord::Base
|
||||||
|
|
||||||
def articles_for_ordering
|
def articles_for_ordering
|
||||||
if stockit?
|
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,
|
StockArticle.available.all(:include => :article_category,
|
||||||
:order => 'article_categories.name, articles.name').reject{ |a|
|
: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 }
|
}.group_by { |a| a.article_category.name }
|
||||||
else
|
else
|
||||||
supplier.articles.available.all.group_by { |a| a.article_category.name }
|
supplier.articles.available.all.group_by { |a| a.article_category.name }
|
||||||
|
|
Loading…
Reference in a new issue