Commit 65e9fc03453a1e8507a1d86505873be07346eff0

Authored by Daniela Feitosa
2 parents fbfb6b11 2281745e

Merge commit 'refs/merge-requests/185' of git://gitorious.org/noosfero/noosfero …

…into merge-requests/185
app/models/input.rb
... ... @@ -9,6 +9,8 @@ class Input < ActiveRecord::Base
9 9  
10 10 belongs_to :unit
11 11  
  12 + named_scope :relevant_to_price, :conditions => { :relevant_to_price => true }
  13 +
12 14 include FloatHelper
13 15  
14 16 def price_per_unit=(value)
... ...
app/models/product.rb
... ... @@ -158,7 +158,7 @@ class Product < ActiveRecord::Base
158 158  
159 159 def inputs_cost
160 160 return 0 if inputs.empty?
161   - inputs.map(&:cost).inject { |sum,price| sum + price }
  161 + inputs.relevant_to_price.map(&:cost).inject { |sum,price| sum + price }
162 162 end
163 163  
164 164 def total_production_cost
... ...
test/unit/input_test.rb
... ... @@ -177,4 +177,18 @@ class InputTest < ActiveSupport::TestCase
177 177 assert_equal 0.00, input.cost
178 178 end
179 179  
  180 + should 'list inputs relevants to price' do
  181 + product_category = fast_create(ProductCategory)
  182 + product = fast_create(Product, :product_category_id => product_category.id)
  183 +
  184 + i1 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => true)
  185 +
  186 + i2 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => false)
  187 +
  188 + i1.save!
  189 + i2.save!
  190 + assert_includes Input.relevant_to_price, i1
  191 + assert_not_includes Input.relevant_to_price, i2
  192 + end
  193 +
180 194 end
... ...