From 5984f7e14926df020430a6be2292e6070cfd447d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Trung=20Le=CC=82?= Date: Thu, 19 Jan 2012 17:42:39 +1100 Subject: [PATCH] Refactor Product recalculate_count_on_hand method --- core/app/models/spree/product.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/app/models/spree/product.rb b/core/app/models/spree/product.rb index 3a5b57dc954..fa563bfa926 100644 --- a/core/app/models/spree/product.rb +++ b/core/app/models/spree/product.rb @@ -180,8 +180,7 @@ def self.like_any(fields, values) private def recalculate_count_on_hand product_count_on_hand = has_variants? ? - variants.inject(0) { |acc, v| acc + v.count_on_hand } : - (master ? master.count_on_hand : 0) + variants.sum(:count_on_hand) : (master ? master.count_on_hand : 0) self.count_on_hand = product_count_on_hand end