Skip to content

Commit

Permalink
Refactor Product recalculate_count_on_hand method
Browse files Browse the repository at this point in the history
  • Loading branch information
Trung Lê committed Jan 19, 2012
1 parent 90f6d51 commit 5984f7e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 5984f7e

Please sign in to comment.