Add EnterpriseFee model

This commit is contained in:
Rohan Mitchell
2012-11-15 13:42:55 +11:00
parent 9cb5ac95ff
commit 192d4993a1
5 changed files with 116 additions and 75 deletions

View File

@@ -0,0 +1,8 @@
class EnterpriseFee < ActiveRecord::Base
belongs_to :enterprise
FEE_TYPES = %w(Packing Transport Admin Sales)
validates_inclusion_of :fee_type, :in => FEE_TYPES
validates_presence_of :name
end

View File

@@ -0,0 +1,11 @@
class CreateEnterpriseFees < ActiveRecord::Migration
def change
create_table :enterprise_fees do |t|
t.references :enterprise
t.string :fee_type
t.string :name
t.timestamps
end
end
end

View File

@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20121031222403) do
ActiveRecord::Schema.define(:version => 20121115010717) do
create_table "cms_blocks", :force => true do |t|
t.integer "page_id", :null => false
@@ -130,6 +130,14 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
add_index "cms_snippets", ["site_id", "identifier"], :name => "index_cms_snippets_on_site_id_and_identifier", :unique => true
add_index "cms_snippets", ["site_id", "position"], :name => "index_cms_snippets_on_site_id_and_position"
create_table "enterprise_fees", :force => true do |t|
t.integer "enterprise_id"
t.string "fee_type"
t.string "name"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "enterprises", :force => true do |t|
t.string "name"
t.string "description"
@@ -186,8 +194,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "alternative_phone"
t.integer "state_id"
t.integer "country_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "company"
end
@@ -196,12 +204,12 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "spree_adjustments", :force => true do |t|
t.integer "source_id"
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0
t.decimal "amount", :precision => 8, :scale => 2
t.string "label"
t.string "source_type"
t.integer "adjustable_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "mandatory"
t.boolean "locked"
t.integer "originator_id"
@@ -233,15 +241,15 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "type"
t.integer "calculable_id", :null => false
t.string "calculable_type", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_configurations", :force => true do |t|
t.string "name"
t.string "type", :limit => 50
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "spree_configurations", ["name", "type"], :name => "index_configurations_on_name_and_type"
@@ -279,8 +287,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "environment", :default => "development"
t.string "server", :default => "test"
t.boolean "test_mode", :default => true
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_inventory_units", :force => true do |t|
@@ -288,8 +296,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "state"
t.integer "variant_id"
t.integer "order_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "shipment_id"
t.integer "return_authorization_id"
end
@@ -303,8 +311,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "variant_id"
t.integer "quantity", :null => false
t.decimal "price", :precision => 8, :scale => 2, :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "max_quantity"
t.integer "shipping_method_id"
end
@@ -316,22 +324,22 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "source_id"
t.string "source_type"
t.text "details"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_mail_methods", :force => true do |t|
t.string "environment"
t.boolean "active", :default => true
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_option_types", :force => true do |t|
t.string "name", :limit => 100
t.string "presentation", :limit => 100
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "position", :default => 0, :null => false
end
@@ -345,8 +353,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "name"
t.string "presentation"
t.integer "option_type_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_option_values_variants", :id => false, :force => true do |t|
@@ -365,8 +373,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.decimal "adjustment_total", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.decimal "credit_total", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "completed_at"
t.integer "bill_address_id"
t.integer "ship_address_id"
@@ -387,8 +395,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.text "description"
t.boolean "active", :default => true
t.string "environment", :default => "development"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.datetime "deleted_at"
t.string "display_on"
end
@@ -396,8 +404,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "spree_payments", :force => true do |t|
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.integer "order_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "source_id"
t.string "source_type"
t.integer "payment_method_id"
@@ -426,8 +434,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "owner_id"
t.string "owner_type"
t.text "value"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "key"
t.string "value_type"
end
@@ -452,16 +460,16 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "position"
t.integer "product_id"
t.integer "option_type_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_product_properties", :force => true do |t|
t.string "value"
t.integer "product_id"
t.integer "property_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "spree_product_properties", ["product_id"], :name => "index_product_properties_on_product_id"
@@ -485,8 +493,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "meta_keywords"
t.integer "tax_category_id"
t.integer "shipping_category_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "count_on_hand", :default => 0, :null => false
t.integer "supplier_id"
t.boolean "group_buy"
@@ -531,8 +539,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "user_id"
t.integer "product_group_id"
t.string "type"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "spree_promotion_rules", ["product_group_id"], :name => "index_promotion_rules_on_product_group_id"
@@ -549,8 +557,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "spree_properties", :force => true do |t|
t.string "name"
t.string "presentation", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_properties_prototypes", :id => false, :force => true do |t|
@@ -560,8 +568,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "spree_prototypes", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_return_authorizations", :force => true do |t|
@@ -570,8 +578,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.decimal "amount", :precision => 8, :scale => 2, :default => 0.0, :null => false
t.integer "order_id"
t.text "reason"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_roles", :force => true do |t|
@@ -594,8 +602,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "order_id"
t.integer "shipping_method_id"
t.integer "address_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "state"
end
@@ -603,15 +611,15 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "spree_shipping_categories", :force => true do |t|
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_shipping_methods", :force => true do |t|
t.string "name"
t.integer "zone_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "display_on"
t.integer "shipping_category_id"
t.boolean "match_none"
@@ -627,8 +635,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "transaction_id"
t.integer "customer_id"
t.string "payment_type"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_state_changes", :force => true do |t|
@@ -636,8 +644,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "previous_state"
t.integer "stateful_id"
t.integer "user_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "stateful_type"
t.string "next_state"
end
@@ -651,8 +659,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
create_table "spree_tax_categories", :force => true do |t|
t.string "name"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "is_default", :default => false
t.datetime "deleted_at"
end
@@ -661,15 +669,15 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.decimal "amount", :precision => 8, :scale => 5
t.integer "zone_id"
t.integer "tax_category_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "included_in_price", :default => false
end
create_table "spree_taxonomies", :force => true do |t|
t.string "name", :null => false
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_taxons", :force => true do |t|
@@ -678,8 +686,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "name", :null => false
t.string "permalink"
t.integer "taxonomy_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.integer "lft"
t.integer "rgt"
t.string "icon_file_name"
@@ -697,8 +705,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "permissable_id"
t.string "permissable_type"
t.string "token"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "spree_tokenized_permissions", ["permissable_id", "permissable_type"], :name => "index_tokenized_name_and_type"
@@ -707,8 +715,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "environment"
t.string "analytics_id"
t.boolean "active", :default => true
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_users", :force => true do |t|
@@ -729,8 +737,8 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.string "login"
t.integer "ship_address_id"
t.integer "bill_address_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "authentication_token"
t.string "unlock_token"
t.datetime "locked_at"
@@ -753,7 +761,7 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.boolean "is_master", :default => false
t.integer "product_id"
t.integer "count_on_hand", :default => 0, :null => false
t.decimal "cost_price", :precision => 8, :scale => 2, :default => 0.0
t.decimal "cost_price", :precision => 8, :scale => 2
t.integer "position"
end
@@ -763,15 +771,15 @@ ActiveRecord::Schema.define(:version => 20121031222403) do
t.integer "zoneable_id"
t.string "zoneable_type"
t.integer "zone_id"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "spree_zones", :force => true do |t|
t.string "name"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.boolean "default_tax", :default => false
t.integer "zone_members_count", :default => 0
end

View File

@@ -20,6 +20,9 @@ FactoryGirl.define do
is_distributor true
end
factory :enterprise_fee, :class => EnterpriseFee do
end
factory :product_distribution, :class => ProductDistribution do
product { |pd| Spree::Product.first || FactoryGirl.create(:product) }
distributor { |pd| Enterprise.is_distributor.first || FactoryGirl.create(:distributor_enterprise) }

View File

@@ -0,0 +1,11 @@
require 'spec_helper'
describe EnterpriseFee do
describe "associations" do
it { should belong_to(:enterprise) }
end
describe "validations" do
it { should validate_presence_of(:name) }
end
end