use plain Ruby memoization to fix deprecation (closes #121)
This commit is contained in:
parent
6b0146eb95
commit
c7f28a3b5c
2 changed files with 41 additions and 41 deletions
|
@ -1,6 +1,5 @@
|
|||
# encoding: utf-8
|
||||
class Article < ActiveRecord::Base
|
||||
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
|
||||
|
||||
# Replace numeric seperator with database format
|
||||
localize_input_of :price, :tax, :deposit
|
||||
|
@ -44,11 +43,12 @@ class Article < ActiveRecord::Base
|
|||
|
||||
# If the article is used in an open Order, the Order will be returned.
|
||||
def in_open_order
|
||||
@in_open_order ||= begin
|
||||
order_articles = OrderArticle.all(:conditions => ['order_id IN (?)', Order.open.collect(&:id)])
|
||||
order_article = order_articles.detect {|oa| oa.article_id == id }
|
||||
order_article ? order_article.order : nil
|
||||
end
|
||||
memoize :in_open_order
|
||||
end
|
||||
|
||||
# Returns true if the article has been ordered in the given order at least once
|
||||
def ordered_in_order?(order)
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
# The chronologically order of the Ordergroup - activity are stored in GroupOrderArticleQuantity
|
||||
#
|
||||
class GroupOrderArticle < ActiveRecord::Base
|
||||
extend ActiveSupport::Memoizable # Ability to cache method results. Use memoize :expensive_method
|
||||
|
||||
belongs_to :group_order
|
||||
belongs_to :order_article
|
||||
|
@ -101,6 +100,7 @@ class GroupOrderArticle < ActiveRecord::Base
|
|||
#
|
||||
# See description of the ordering algorithm in the general application documentation for details.
|
||||
def calculate_result
|
||||
@calculate_result ||= begin
|
||||
quantity = tolerance = 0
|
||||
stockit = order_article.article.is_a?(StockArticle)
|
||||
|
||||
|
@ -148,7 +148,7 @@ class GroupOrderArticle < ActiveRecord::Base
|
|||
|
||||
{:quantity => quantity, :tolerance => tolerance, :total => quantity + tolerance}
|
||||
end
|
||||
memoize :calculate_result
|
||||
end
|
||||
|
||||
# Returns order result,
|
||||
# either calcualted on the fly or fetched from result attribute
|
||||
|
|
Loading…
Reference in a new issue