Rename Enterprise is_supplier scope to is_primary_producer

This commit is contained in:
Rohan Mitchell
2012-11-01 15:02:57 +11:00
parent a7a8b8490b
commit c2133d70ac
6 changed files with 8 additions and 9 deletions

View File

@@ -9,9 +9,8 @@ class ApplicationController < ActionController::Base
@cms_site = Cms::Site.where(:identifier => 'open-food-web').first
end
def load_data_for_sidebar
@suppliers = Enterprise.is_supplier.all
@suppliers = Enterprise.is_primary_producer
@distributors = Enterprise.is_distributor.with_distributed_active_products_on_hand.by_name
end

View File

@@ -4,7 +4,7 @@ class EnterprisesController < BaseController
end
def suppliers
@suppliers = Enterprise.is_supplier
@suppliers = Enterprise.is_primary_producer
end
def distributors

View File

@@ -15,7 +15,7 @@ class Enterprise < ActiveRecord::Base
before_validation :set_unused_address_fields
scope :by_name, order('name')
scope :is_supplier, where(:is_primary_producer => true)
scope :is_primary_producer, where(:is_primary_producer => true)
scope :is_distributor, where(:is_distributor => true)
scope :with_distributed_active_products_on_hand, lambda { joins(:distributed_products).where('spree_products.deleted_at IS NULL AND spree_products.available_on <= ? AND spree_products.count_on_hand > 0', Time.now).select('distinct(enterprises.*)') }

View File

@@ -1,5 +1,5 @@
= f.field_container :supplier do
= f.label :supplier
%br
= f.collection_select(:supplier_id, Enterprise.is_supplier, :id, :name, :include_blank => true)
= f.collection_select(:supplier_id, Enterprise.is_primary_producer, :id, :name, :include_blank => true)
= f.error_message_on :supplier

View File

@@ -74,19 +74,19 @@ unless Spree::Product.count > 0
FactoryGirl.create(:product,
:name => 'Garlic', :price => 20.00,
:supplier => Enterprise.is_supplier[0],
:supplier => Enterprise.is_primary_producer[0],
:distributors => [Enterprise.is_distributor[0]],
:taxons => [Spree::Taxon.find_by_name('Vegetables')])
FactoryGirl.create(:product,
:name => 'Fuji Apple', :price => 5.00,
:supplier => Enterprise.is_supplier[1],
:supplier => Enterprise.is_primary_producer[1],
:distributors => Enterprise.is_distributor,
:taxons => [Spree::Taxon.find_by_name('Fruit')])
FactoryGirl.create(:product,
:name => 'Beef - 5kg Trays', :price => 50.00,
:supplier => Enterprise.is_supplier[2],
:supplier => Enterprise.is_primary_producer[2],
:distributors => [Enterprise.is_distributor[2]],
:taxons => [Spree::Taxon.find_by_name('Meat and Fish')])
end

View File

@@ -43,7 +43,7 @@ FactoryGirl.modify do
# When this fix has been merged into a version of Spree that we're using, this line can be removed.
sequence(:name) { |n| "Product ##{n} - #{Kernel.rand(9999)}" }
supplier { Enterprise.is_supplier.first || FactoryGirl.create(:supplier_enterprise) }
supplier { Enterprise.is_primary_producer.first || FactoryGirl.create(:supplier_enterprise) }
on_hand 3
# before(:create) do |product, evaluator|