From 6bf3b241e6a34b7ce5a5d704df5dc1573ad40951 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Wed, 6 Mar 2013 14:19:06 +0100 Subject: [PATCH 1/3] Do not subtract articles in open orders when calculating quantity. --- app/models/stock_article.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 6050c8c4..71679e93 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -16,7 +16,7 @@ class StockArticle < Article # Check for unclosed orders and substract its ordered quantity def quantity_available quantity - OrderArticle.where(article_id: id). - joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order) + joins(:order).where("orders.state = 'finished'").sum(:units_to_order) end def self.stock_value From 93a99c45d82331cf32583ddf97178f7b769f9fbd Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Thu, 7 Mar 2013 20:39:35 +0100 Subject: [PATCH 2/3] Revert "Do not subtract articles in open orders when calculating quantity." This reverts commit 6bf3b241e6a34b7ce5a5d704df5dc1573ad40951. --- app/models/stock_article.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/stock_article.rb b/app/models/stock_article.rb index 71679e93..6050c8c4 100644 --- a/app/models/stock_article.rb +++ b/app/models/stock_article.rb @@ -16,7 +16,7 @@ class StockArticle < Article # Check for unclosed orders and substract its ordered quantity def quantity_available quantity - OrderArticle.where(article_id: id). - joins(:order).where("orders.state = 'finished'").sum(:units_to_order) + joins(:order).where("orders.state = 'open' OR orders.state = 'finished'").sum(:units_to_order) end def self.stock_value From 63d8a3a1a63cfac4a3949576464cb21fdae8da13 Mon Sep 17 00:00:00 2001 From: Robert Waltemath Date: Thu, 7 Mar 2013 20:43:02 +0100 Subject: [PATCH 3/3] Do not exclude ordered articles (with zero quantity) when editing orders. --- app/models/article.rb | 4 ++++ app/models/order.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/article.rb b/app/models/article.rb index 09f17fa4..85c02577 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -48,6 +48,10 @@ class Article < ActiveRecord::Base order_article ? order_article.order : nil end memoize :in_open_order + + def ordered?(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 diff --git a/app/models/order.rb b/app/models/order.rb index 6e48756c..a59d20f7 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -41,7 +41,7 @@ class Order < ActiveRecord::Base if stockit? 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?(self) }.group_by { |a| a.article_category.name } else supplier.articles.available.all.group_by { |a| a.article_category.name }