diff --git a/app/models/input.rb b/app/models/input.rb index 541fbc4..df88ac6 100644 --- a/app/models/input.rb +++ b/app/models/input.rb @@ -9,6 +9,8 @@ class Input < ActiveRecord::Base belongs_to :unit + named_scope :relevant_to_price, :conditions => { :relevant_to_price => true } + include FloatHelper def price_per_unit=(value) diff --git a/app/models/product.rb b/app/models/product.rb index 9d74d19..5040c7a 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -175,7 +175,7 @@ class Product < ActiveRecord::Base def inputs_cost return 0 if inputs.empty? - inputs.map(&:cost).inject { |sum,price| sum + price } + inputs.relevant_to_price.map(&:cost).inject { |sum,price| sum + price } end def total_production_cost diff --git a/test/unit/input_test.rb b/test/unit/input_test.rb index 470b2f5..c136dab 100644 --- a/test/unit/input_test.rb +++ b/test/unit/input_test.rb @@ -177,4 +177,18 @@ class InputTest < ActiveSupport::TestCase assert_equal 0.00, input.cost end + should 'list inputs relevants to price' do + product_category = fast_create(ProductCategory) + product = fast_create(Product, :product_category_id => product_category.id) + + i1 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => true) + + i2 = Input.create!(:product => product, :product_category => product_category, :relevant_to_price => false) + + i1.save! + i2.save! + assert_includes Input.relevant_to_price, i1 + assert_not_includes Input.relevant_to_price, i2 + end + end -- libgit2 0.21.2