Merge pull request #99 from balkansalat/rails3-fix-stock-ordering-2
Prevent sold-out articles from being removed from stock order when editing
This commit is contained in:
commit
28343fc124
2 changed files with 8 additions and 1 deletions
|
@ -49,6 +49,11 @@ class Article < ActiveRecord::Base
|
|||
end
|
||||
memoize :in_open_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
|
||||
|
||||
# this method checks, if the shared_article has been changed
|
||||
# unequal attributes will returned in array
|
||||
# if only the timestamps differ and the attributes are equal,
|
||||
|
|
|
@ -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
|
||||
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 }
|
||||
|
|
Loading…
Reference in a new issue