erp_products 4.0.0 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/api/v1/product_types_controller.rb +140 -0
  3. data/app/controllers/erp_products/shared/product_features_controller.rb +46 -0
  4. data/app/models/extensions/biz_txn_acct_root.rb +5 -0
  5. data/app/models/product_feature.rb +117 -0
  6. data/app/models/product_feature_applicability.rb +17 -0
  7. data/app/models/product_feature_interaction.rb +21 -0
  8. data/app/models/product_feature_interaction_type.rb +17 -0
  9. data/app/models/product_feature_type.rb +70 -0
  10. data/app/models/product_feature_type_product_feature_value.rb +16 -0
  11. data/app/models/product_feature_value.rb +42 -0
  12. data/app/models/product_instance.rb +4 -0
  13. data/app/models/product_offer.rb +25 -3
  14. data/app/models/product_type.rb +185 -21
  15. data/app/models/product_type_pty_role.rb +2 -0
  16. data/app/models/simple_product_offer.rb +3 -1
  17. data/config/routes.rb +15 -4
  18. data/db/data_migrations/20141222195727_add_product_type_view_types.rb +24 -0
  19. data/db/migrate/20080805000040_base_products.rb +284 -136
  20. data/db/migrate/20150304211841_add_shipping_cost_to_product_types.rb +7 -0
  21. data/db/migrate/20150507075057_add_dimensions_to_product_types.rb +12 -0
  22. data/db/migrate/20150622150625_add_taxable_to_product_types.rb +5 -0
  23. data/db/migrate/20150711194216_update_product_feature_interactions.rb +21 -0
  24. data/db/migrate/20151216235328_add_biz_txn_acct_root_to_products.rb +15 -0
  25. data/db/migrate/20160310163055_add_created_by_updated_by_to_erp_products.rb +43 -0
  26. data/lib/erp_products/engine.rb +0 -4
  27. data/lib/erp_products/extensions/active_record/acts_as_product_offer.rb +7 -4
  28. data/lib/erp_products/version.rb +1 -1
  29. metadata +24 -14
  30. data/app/controllers/erp_products/shared/product_types_controller.rb +0 -96
  31. data/app/views/erp_products/shared/product_types/show_details.html.erb +0 -8
  32. data/db/migrate/20080805000041_base_products_indexes.rb +0 -61
  33. data/db/migrate/20130131204335_add_product_instances_nested_set_indexes.rb +0 -9
  34. data/db/migrate/20130131204336_add_type_column_to_product_types.rb +0 -9
  35. data/db/migrate/20140124185720_add_product_party_roles.rb +0 -17
  36. data/db/migrate/20140130211433_add_sku_comment_uom_to_product_type.rb +0 -7
@@ -0,0 +1,16 @@
1
+ # create_table :product_feature_type_product_feature_values do |t|
2
+ # t.references :product_feature_type
3
+ # t.references :product_feature_value
4
+ #
5
+ # t.timestamps
6
+ # end
7
+ #
8
+ # add_index :product_feature_type_product_feature_values, :product_feature_type_id, :name => 'prod_feature_type_feature_value_type_idx'
9
+ # add_index :product_feature_type_product_feature_values, :product_feature_value_id, :name => 'prod_feature_type_feature_value_value_idx'#
10
+
11
+ class ProductFeatureTypeProductFeatureValue < ActiveRecord::Base
12
+ attr_protected :created_at, :updated_at
13
+
14
+ belongs_to :product_feature_type
15
+ belongs_to :product_feature_value
16
+ end
@@ -0,0 +1,42 @@
1
+ # create_table :product_feature_values do |t|
2
+ # t.string :value
3
+ # t.string :internal_identifier
4
+ # t.string :external_identifier
5
+ # t.string :external_id_source
6
+ # t.string :description
7
+ #
8
+ # t.timestamps
9
+ # end
10
+ #
11
+ # add_index :product_feature_values, :internal_identifier, name: 'product_ft_vals_iid_idx'
12
+
13
+ class ProductFeatureValue < ActiveRecord::Base
14
+ attr_protected :created_at, :updated_at
15
+
16
+ tracks_created_by_updated_by
17
+
18
+ has_many :product_feature_type_product_feature_values, dependent: :destroy
19
+ has_many :product_feature_types, through: :product_feature_type_product_feature_values
20
+
21
+ has_many :product_features, dependent: :destroy
22
+
23
+ def self.find_or_create(internal_identifier, description, product_feature_type=nil)
24
+ product_feature_value = ProductFeatureValue.joins(:product_feature_type_product_feature_values)
25
+ .where(internal_identifier: internal_identifier).readonly(false).first
26
+
27
+ unless product_feature_value
28
+ product_feature_value = ProductFeatureValue.create(description: description,
29
+ internal_identifier: internal_identifier)
30
+
31
+ end
32
+
33
+ if product_feature_type
34
+ unless product_feature_value.product_feature_types.collect(&:id).include?(product_feature_type.id)
35
+ product_feature_value.product_feature_types << product_feature_type
36
+ product_feature_value.save
37
+ end
38
+ end
39
+
40
+ product_feature_value
41
+ end
42
+ end
@@ -18,5 +18,9 @@ class ProductInstance < ActiveRecord::Base
18
18
  def prod_instance_relns_from
19
19
  ProdInstanceReln.where('prod_instance_id_from = ?',id)
20
20
  end
21
+
22
+ def taxable?
23
+ self.product_type.taxable?
24
+ end
21
25
 
22
26
  end
@@ -1,12 +1,34 @@
1
1
  class ProductOffer < ActiveRecord::Base
2
2
  attr_protected :created_at, :updated_at
3
-
4
- belongs_to :product_offer_record, :polymorphic => true
3
+
4
+ tracks_created_by_updated_by
5
+
6
+ belongs_to :product_offer_record, :polymorphic => true
7
+
8
+ def valid_from=(date)
9
+ if date.is_a? String
10
+ write_attribute(:valid_from, date.to_date)
11
+ else
12
+ super
13
+ end
14
+ end
15
+
16
+ def valid_to=(date)
17
+ if date.is_a? String
18
+ write_attribute(:valid_to, date.to_date)
19
+ else
20
+ super
21
+ end
22
+ end
5
23
 
6
24
  def after_destroy
7
25
  if self.product_offer_record && !self.product_offer_record.frozen?
8
26
  self.product_offer_record.destroy
9
27
  end
10
- end
28
+ end
29
+
30
+ def taxable?
31
+ self.product_offer_record.taxable?
32
+ end
11
33
 
12
34
  end
@@ -1,29 +1,138 @@
1
+ # create_table :product_types do |t|
2
+ # #these columns are required to support the behavior of the plugin 'better_nested_set'
3
+ # #ALL products have the ability to act as packages in a nested set-type structure
4
+ # #
5
+ # #The package behavior is treated differently from other product_relationship behavior
6
+ # #which is implemented using a standard relationship structure.
7
+ # #
8
+ # #This is to allow quick construction of highly nested product types.
9
+ # t.column :parent_id, :integer
10
+ # t.column :lft, :integer
11
+ # t.column :rgt, :integer
12
+ #
13
+ # #custom columns go here
14
+ # t.column :description, :string
15
+ # t.column :product_type_record_id, :integer
16
+ # t.column :product_type_record_type, :string
17
+ # t.column :external_identifier, :string
18
+ # t.column :internal_identifier, :string
19
+ # t.column :external_id_source, :string
20
+ # t.column :default_image_url, :string
21
+ # t.column :list_view_image_id, :integer
22
+ # t.column :length, :decimal
23
+ # t.column :width, :decimal
24
+ # t.column :height, :decimal
25
+ # t.column :weight, :decimal
26
+ # t.column :cylindrical, :boolean
27
+ # t.column :taxable :boolean
28
+ # t.column :available_on_web :boolean
29
+ # t.references :unit_of_measurement
30
+ # t.references :biz_txn_acct_root
31
+ #
32
+ # t.timestamps
33
+ # end
34
+ #
35
+ # add_index :product_types, :biz_txn_acct_root_id
36
+
1
37
  class ProductType < ActiveRecord::Base
2
38
  attr_protected :created_at, :updated_at
3
39
 
4
40
  acts_as_nested_set
5
41
  include ErpTechSvcs::Utils::DefaultNestedSetMethods
6
-
42
+ acts_as_taggable
43
+
44
+ tracks_created_by_updated_by
7
45
  has_file_assets
8
46
  is_describable
9
-
10
- belongs_to :product_type_record, :polymorphic => true
11
- has_one :product_instance
47
+
48
+ belongs_to :product_type_record, polymorphic: true
12
49
  belongs_to :unit_of_measurement
13
- has_many :product_type_pty_roles, :dependent => :destroy
14
-
50
+ belongs_to :biz_txn_acct_root
51
+
52
+ has_one :product_instance
53
+ has_many :product_type_pty_roles, dependent: :destroy
54
+ has_many :simple_product_offers, dependent: :destroy
55
+ has_many :product_feature_applicabilities, dependent: :destroy, as: :feature_of_record
56
+
57
+ validates :internal_identifier, :uniqueness => true, :allow_nil => true
58
+
59
+ alias :gl_account :biz_txn_acct_root
60
+
61
+ class << self
62
+ # Filter records
63
+ #
64
+ # @param filters [Hash] a hash of filters to be applied,
65
+ # @param statement [ActiveRecord::Relation] the query being built
66
+ # @return [ActiveRecord::Relation] the query being built
67
+ def apply_filters(filters, statement=nil)
68
+ unless statement
69
+ statement = ProductType
70
+ end
71
+
72
+ statement
73
+ end
74
+
75
+ #
76
+ # scoping helpers
77
+ #
78
+
79
+ # scope by dba organization
80
+ #
81
+ # @param dba_organization [Party] dba organization to scope by
82
+ #
83
+ # @return [ActiveRecord::Relation]
84
+ def scope_by_dba_organization(dba_organization)
85
+ scope_by_party(dba_organization, {role_types: [RoleType.iid('dba_org')]})
86
+ end
87
+
88
+ # scope by party
89
+ #
90
+ # @param party [Integer | Party | Array] either a id of Party record, a Party record, an array of Party records
91
+ # or an array of Party ids
92
+ # @param options [Hash] options to apply to this scope
93
+ # @option options [Array] :role_types role types to include in the scope
94
+ #
95
+ # @return [ActiveRecord::Relation]
96
+ def scope_by_party(party, options={})
97
+ statement = joins(:product_type_pty_roles).where("product_type_pty_roles.party_id" => party).uniq
98
+
99
+ if options[:role_types]
100
+ statement = statement.where("product_type_pty_roles.role_type_id" => RoleType.find_child_role_types(options[:role_types]))
101
+ end
102
+
103
+ statement
104
+ end
105
+ end
106
+
107
+ # add party with passed role to this ProductType
108
+ #
109
+ # @param party [Party] party to add
110
+ # @param role_type [RoleType] role type to use in the association
111
+ # @return [ProductTypePtyRole] newly created relationship
112
+ def add_party_with_role(party, role_type)
113
+ ProductTypePtyRole.create(
114
+ product_type: self,
115
+ party: party,
116
+ role_type: role_type
117
+ )
118
+ end
119
+
120
+ def taxable?
121
+ self.taxable
122
+ end
123
+
15
124
  def prod_type_relns_to
16
- ProdTypeReln.where('prod_type_id_to = ?',id)
125
+ ProdTypeReln.where('prod_type_id_to = ?', id)
17
126
  end
18
127
 
19
128
  def prod_type_relns_from
20
- ProdTypeReln.where('prod_type_id_from = ?',id)
129
+ ProdTypeReln.where('prod_type_id_from = ?', id)
21
130
  end
22
-
131
+
23
132
  def to_label
24
133
  "#{description}"
25
134
  end
26
-
135
+
27
136
  def to_s
28
137
  "#{description}"
29
138
  end
@@ -31,23 +140,78 @@ class ProductType < ActiveRecord::Base
31
140
  def self.count_by_status(product_type, prod_availability_status_type)
32
141
  ProductInstance.count("product_type_id = #{product_type.id} and prod_availability_status_type_id = #{prod_availability_status_type.id}")
33
142
  end
34
-
143
+
35
144
  def images_path
36
145
  file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage)
37
- File.join(file_support.root,Rails.application.config.erp_tech_svcs.file_assets_location,'products','images',"#{self.description.underscore}_#{self.id}")
146
+ File.join(file_support.root, Rails.application.config.erp_tech_svcs.file_assets_location, 'products', 'images', "#{self.description.underscore}_#{self.id}")
38
147
  end
39
148
 
40
149
  def to_data_hash
150
+ to_hash(only: [
151
+ :id,
152
+ :description,
153
+ :internal_identifier,
154
+ :sku,
155
+ :comment,
156
+ :created_at,
157
+ :updated_at
158
+ ],
159
+ unit_of_measurement: try(:unit_of_measurement).try(:to_data_hash),
160
+ price: try(:get_current_simple_plan).try(:money_amount),
161
+ gl_account: try(:gl_account).try(:to_data_hash))
162
+ end
163
+
164
+ def to_display_hash
41
165
  {
42
- :id => self.id,
43
- :description => self.description,
44
- :sku => self.sku,
45
- :unit_of_measurement_id => self.unit_of_measurement_id,
46
- :unit_of_measurement_description => (self.unit_of_measurement.description rescue nil),
47
- :comment => self.comment,
48
- :created_at => self.created_at,
49
- :updated_at => self.updated_at
166
+ id: id,
167
+ description: description,
168
+ offer_list_description: find_descriptions_by_view_type('list_description').first.try(:description),
169
+ offer_short_description: find_descriptions_by_view_type('short_description').first.try(:description),
170
+ offer_long_description: find_descriptions_by_view_type('long_description').first.try(:description),
171
+ offer_base_price: get_current_simple_amount_with_currency,
172
+ images: images.pluck(:id)
50
173
  }
51
174
  end
52
-
175
+
176
+ def parent_dba_organizations(dba_orgs=[])
177
+ ProductTypePtyRole.
178
+ where('product_type_id = ?', id).
179
+ where('role_type_id' => RoleType.iid('dba_org').id).each do |prod_party_reln|
180
+
181
+ dba_orgs.push(prod_party_reln.party)
182
+ prod_party_reln.party.parent_dba_organizations(dba_orgs)
183
+ end
184
+
185
+ dba_orgs.uniq
186
+ end
187
+
188
+ def add_party_with_role_type(party, role_type)
189
+ if role_type.is_a?(String)
190
+ role_type = RoleType.iid(role_type)
191
+ end
192
+
193
+ ProductTypePtyRole.create(party: party, role_type: role_type, product_type: self)
194
+ end
195
+
196
+ def has_dimensions?
197
+ (cylindrical && length && width && weight) or (length && width && height && weight)
198
+ end
53
199
  end
200
+
201
+ module Arel
202
+ class SelectManager
203
+ def polymorphic_join(hash={polytable: nil, table: nil, model: nil, polymodel: nil, record_type_name: nil, record_id_name: nil, table_model: nil})
204
+ # Left Outer Join with 2 possible hash argument sets:
205
+ # 1) model (AR model), polymodel (AR model), record_type_name (symbol), record_id_name (symbol)
206
+ # 2) polytable (arel_table), table (arel_table), record_type_name (symbol), record_id_name (symbol), table_model (string)
207
+
208
+ if hash[:model] && hash[:polymodel]
209
+ self.join(hash[:polymodel].arel_table, Arel::Nodes::OuterJoin).on(hash[:polymodel].arel_table[hash[:record_id_name]].eq(hash[:model].arel_table[:id]).and(hash[:polymodel].arel_table[hash[:record_type_name]].eq(hash[:model].to_s)))
210
+ elsif hash[:polytable] && hash[:record_type_name]
211
+ self.join(hash[:polytable], Arel::Nodes::OuterJoin).on(hash[:polytable][hash[:record_id_name]].eq(hash[:table][:id]).and(hash[:polytable][hash[:record_type_name]].eq(hash[:table_model])))
212
+ else
213
+ raise 'Invalid Args'
214
+ end
215
+ end
216
+ end
217
+ end
@@ -1,4 +1,6 @@
1
1
  class ProductTypePtyRole < ActiveRecord::Base
2
+ attr_protected :created_at, :updated_at
3
+
2
4
  belongs_to :product_type
3
5
  belongs_to :party
4
6
  belongs_to :role_type
@@ -1,6 +1,8 @@
1
1
  class SimpleProductOffer < ActiveRecord::Base
2
2
  attr_protected :created_at, :updated_at
3
3
 
4
+ is_json :custom_fields
4
5
  acts_as_product_offer
5
- belongs_to :product
6
+
7
+ belongs_to :product_type
6
8
  end
@@ -1,9 +1,20 @@
1
+ Rails.application.routes.draw do
2
+
3
+ namespace :api do
4
+ namespace :v1 do
5
+
6
+ resources :product_types, defaults: { :format => 'json' }
7
+
8
+ end
9
+ end
10
+
11
+ end
12
+
1
13
  ErpProducts::Engine.routes.draw do
2
- #product_manager
3
- match '/erp_app/desktop/product_manager(/:action(/:id))' => 'erp_app/desktop/product_manager/base'
4
14
 
5
15
  namespace 'shared' do
6
- resources 'product_types'
7
- get 'product_types/show_details(/:id)' => 'product_types#show_details'
16
+ resources :product_features, except: [:show]
17
+ get '/product_features/get_values' => 'product_features#get_values'
8
18
  end
19
+
9
20
  end
@@ -0,0 +1,24 @@
1
+ class AddProductTypeViewTypes
2
+
3
+ def self.up
4
+ product_type_view_type = ViewType.create(description: 'Product Type Descriptions',
5
+ internal_identifier: 'product_type_description')
6
+
7
+ list = ViewType.create(description: 'List Description',
8
+ internal_identifier: 'list_description')
9
+ list.move_to_child_of(product_type_view_type)
10
+
11
+ short = ViewType.create(description: 'Short Description',
12
+ internal_identifier: 'short_description')
13
+ short.move_to_child_of(product_type_view_type)
14
+
15
+ long = ViewType.create(description: 'Long Description',
16
+ internal_identifier: 'long_description')
17
+ long.move_to_child_of(product_type_view_type)
18
+ end
19
+
20
+ def self.down
21
+ #remove data here
22
+ end
23
+
24
+ end
@@ -1,6 +1,7 @@
1
1
  class BaseProducts < ActiveRecord::Migration
2
2
  def self.up
3
-
3
+
4
+ # product_types
4
5
  unless table_exists?(:product_types)
5
6
  create_table :product_types do |t|
6
7
  #these columns are required to support the behavior of the plugin 'better_nested_set'
@@ -10,23 +11,34 @@ class BaseProducts < ActiveRecord::Migration
10
11
  #which is implemented using a standard relationship structure.
11
12
  #
12
13
  #This is to allow quick construction of highly nested product types.
13
- t.column :parent_id, :integer
14
- t.column :lft, :integer
15
- t.column :rgt, :integer
14
+ t.column :parent_id, :integer
15
+ t.column :lft, :integer
16
+ t.column :rgt, :integer
16
17
 
17
18
  #custom columns go here
18
- t.column :description, :string
19
- t.column :product_type_record_id, :integer
20
- t.column :product_type_record_type, :string
21
- t.column :external_identifier, :string
22
- t.column :internal_identifier, :string
23
- t.column :external_id_source, :string
24
- t.column :default_image_url, :string
25
- t.column :list_view_image_id, :integer
19
+ t.column :description, :string
20
+ t.column :product_type_record_id, :integer
21
+ t.column :product_type_record_type, :string
22
+ t.column :external_identifier, :string
23
+ t.column :internal_identifier, :string
24
+ t.column :external_id_source, :string
25
+ t.column :default_image_url, :string
26
+ t.column :list_view_image_id, :integer
27
+ t.column :type, :string
28
+ t.string :sku
29
+ t.text :comment
30
+ t.references :unit_of_measurement
26
31
  t.timestamps
27
32
  end
33
+
34
+ add_index :product_types, :parent_id, :name => "prod_type_parent_id_idx"
35
+ add_index :product_types, :lft, :name => "prod_type_lft_idx"
36
+ add_index :product_types, :rgt, :name => "prod_type_rgt_idx"
37
+ add_index :product_types, :unit_of_measurement_id, :name => "prod_type_uom_idx"
38
+ add_index :product_types, [:product_type_record_id, :product_type_record_type], :name => "prod_type_poly_idx"
28
39
  end
29
-
40
+
41
+ # product_instances
30
42
  unless table_exists?(:product_instances)
31
43
  create_table :product_instances do |t|
32
44
  #these columns are required to support the behavior of the plugin 'better_nested_set'
@@ -36,194 +48,330 @@ class BaseProducts < ActiveRecord::Migration
36
48
  #which is implemented using a standard relationship structure.
37
49
  #
38
50
  #This is to allow quick construction of highly nested product types.
39
- t.column :parent_id, :integer
40
- t.column :lft, :integer
41
- t.column :rgt, :integer
51
+ t.column :parent_id, :integer
52
+ t.column :lft, :integer
53
+ t.column :rgt, :integer
42
54
 
43
55
  #custom columns go here
44
- t.column :description, :string
45
- t.column :product_instance_record_id, :integer
46
- t.column :product_instance_record_type, :string
47
- t.column :external_identifier, :string
48
- t.column :external_id_source, :string
49
- t.column :product_type_id, :integer
50
- t.column :type, :string
56
+ t.column :description, :string
57
+ t.column :product_instance_record_id, :integer
58
+ t.column :product_instance_record_type, :string
59
+ t.column :external_identifier, :string
60
+ t.column :external_id_source, :string
61
+ t.column :product_type_id, :integer
62
+ t.column :type, :string
51
63
 
52
64
  t.references :prod_availability_status_type
53
65
 
54
66
  t.timestamps
55
67
  end
68
+
69
+ add_index :product_instances, :parent_id, :name => "prod_ins_parent_id_idx"
70
+ add_index :product_instances, :lft, :name => "prod_ins_lft_idx"
71
+ add_index :product_instances, :rgt, :name => "prod_ins_rgt_idx"
72
+ add_index :product_instances, [:product_instance_record_id, :product_instance_record_type], :name => "prod_ins_poly_idx"
73
+ add_index :product_instances, :product_type_id, :name => "prod_ins_prod_type_idx"
56
74
  end
57
-
75
+
76
+ # product_offers
58
77
  unless table_exists?(:product_offers)
59
78
  create_table :product_offers do |t|
60
- t.column :description, :string
61
- t.column :product_offer_record_id, :integer
62
- t.column :product_offer_record_type, :string
63
- t.column :external_identifier, :string
64
- t.column :external_id_source, :string
79
+ t.references :product_offer_record, :polymorphic => true
80
+
81
+ t.string :description
82
+ t.string :external_identifier
83
+ t.string :external_id_source
84
+ t.date :valid_from
85
+ t.date :valid_to
86
+
65
87
  t.timestamps
66
88
  end
89
+
90
+ add_index :product_offers, [:product_offer_record_id, :product_offer_record_type], :name => "prod_offer_poly_idx"
91
+ add_index :product_offers, :valid_from, :name => "prod_offer_valid_from_idx"
92
+ add_index :product_offers, :valid_to, :name => "prod_offer_valid_to_idx"
67
93
  end
68
-
94
+
95
+ # simple_product_offers
69
96
  unless table_exists?(:simple_product_offers)
70
97
  create_table :simple_product_offers do |t|
71
- t.column :description, :string
72
- t.column :product_id, :integer
73
- t.column :base_price, :decimal, :precision => 8, :scale => 2
74
- t.column :uom, :integer
98
+ t.references :product_type
99
+
100
+ t.string :description, :string
101
+ t.decimal :base_price, :precision => 8, :scale => 2
102
+ t.integer :uom
103
+
75
104
  t.timestamps
76
105
  end
106
+
107
+ add_index :simple_product_offers, :product_type_id, :name => "simple_prod_offer_product_type_id_idx"
77
108
  end
78
-
109
+
110
+ # prod_instance_reln_types
79
111
  unless table_exists?(:prod_instance_reln_types)
80
112
  create_table :prod_instance_reln_types do |t|
81
- t.column :parent_id, :integer
82
- t.column :lft, :integer
83
- t.column :rgt, :integer
113
+ t.column :parent_id, :integer
114
+ t.column :lft, :integer
115
+ t.column :rgt, :integer
84
116
 
85
117
  #custom columns go here
86
- t.column :description, :string
87
- t.column :comments, :string
88
- t.column :internal_identifier, :string
89
- t.column :external_identifier, :string
90
- t.column :external_id_source, :string
118
+ t.column :description, :string
119
+ t.column :comments, :string
120
+ t.column :internal_identifier, :string
121
+ t.column :external_identifier, :string
122
+ t.column :external_id_source, :string
91
123
  t.timestamps
92
124
  end
125
+
126
+ add_index :prod_instance_reln_types, :parent_id, :name => "prod_reln_type_parent_id_idx"
127
+ add_index :prod_instance_reln_types, :lft, :name => "prod_reln_type_lft_idx"
128
+ add_index :prod_instance_reln_types, :rgt, :name => "prod_reln_type_rgt_idx"
93
129
  end
94
-
130
+
131
+ # prod_instance_role_types
95
132
  unless table_exists?(:prod_instance_role_types)
96
133
  create_table :prod_instance_role_types do |t|
97
- t.column :parent_id, :integer
98
- t.column :lft, :integer
99
- t.column :rgt, :integer
134
+ t.column :parent_id, :integer
135
+ t.column :lft, :integer
136
+ t.column :rgt, :integer
100
137
  #custom columns go here
101
- t.column :description, :string
102
- t.column :comments, :string
103
- t.column :internal_identifier, :string
104
- t.column :external_identifier, :string
105
- t.column :external_id_source, :string
138
+ t.column :description, :string
139
+ t.column :comments, :string
140
+ t.column :internal_identifier, :string
141
+ t.column :external_identifier, :string
142
+ t.column :external_id_source, :string
106
143
  t.timestamps
107
144
  end
145
+
146
+ add_index :prod_instance_role_types, :parent_id, :name => "prod_ins_role_type_parent_id_idx"
147
+ add_index :prod_instance_role_types, :lft, :name => "prod_ins_role_type_lft_idx"
148
+ add_index :prod_instance_role_types, :rgt, :name => "prod_ins_role_type_rgt_idx"
108
149
  end
109
-
150
+
151
+ # prod_instance_relns
110
152
  unless table_exists?(:prod_instance_relns)
111
153
  create_table :prod_instance_relns do |t|
112
- t.column :prod_instance_reln_type_id, :integer
113
- t.column :description, :string
114
- t.column :prod_instance_id_from, :integer
115
- t.column :prod_instance_id_to, :integer
116
- t.column :role_type_id_from, :integer
117
- t.column :role_type_id_to, :integer
118
- t.column :status_type_id, :integer
119
- t.column :from_date, :date
120
- t.column :thru_date, :date
154
+ t.column :prod_instance_reln_type_id, :integer
155
+ t.column :description, :string
156
+ t.column :prod_instance_id_from, :integer
157
+ t.column :prod_instance_id_to, :integer
158
+ t.column :role_type_id_from, :integer
159
+ t.column :role_type_id_to, :integer
160
+ t.column :from_date, :date
161
+ t.column :thru_date, :date
121
162
  t.timestamps
122
163
  end
164
+
165
+ add_index :prod_instance_relns, :prod_instance_reln_type_id, :name => "prod_instance_relns_type_idx"
166
+ add_index :prod_instance_relns, :prod_instance_id_from, :name => "prod_instance_relns_ins_from_idx"
167
+ add_index :prod_instance_relns, :prod_instance_id_to, :name => "prod_instance_relns_ins_to_idx"
168
+ add_index :prod_instance_relns, :role_type_id_from, :name => "prod_instance_relns_type_from_idx"
169
+ add_index :prod_instance_relns, :role_type_id_to, :name => "prod_instance_relns_type_to_idx"
123
170
  end
124
-
171
+
172
+ # prod_type_reln_types
125
173
  unless table_exists?(:prod_type_reln_types)
126
174
  create_table :prod_type_reln_types do |t|
127
- t.column :parent_id, :integer
128
- t.column :lft, :integer
129
- t.column :rgt, :integer
175
+ t.column :parent_id, :integer
176
+ t.column :lft, :integer
177
+ t.column :rgt, :integer
130
178
  #custom columns go here
131
- t.column :description, :string
132
- t.column :comments, :string
133
- t.column :internal_identifier, :string
134
- t.column :external_identifier, :string
135
- t.column :external_id_source, :string
179
+ t.column :description, :string
180
+ t.column :comments, :string
181
+ t.column :internal_identifier, :string
182
+ t.column :external_identifier, :string
183
+ t.column :external_id_source, :string
136
184
  t.timestamps
137
185
  end
186
+
187
+ add_index :prod_instance_role_types, :parent_id, :name => "prod_type_reln_type_parent_id_idx"
188
+ add_index :prod_instance_role_types, :lft, :name => "prod_type_reln_type_lft_idx"
189
+ add_index :prod_instance_role_types, :rgt, :name => "prod_type_reln_type_rgt_idx"
138
190
  end
139
-
191
+
192
+ # prod_type_role_types
140
193
  unless table_exists?(:prod_type_role_types)
141
194
  create_table :prod_type_role_types do |t|
142
- t.column :parent_id, :integer
143
- t.column :lft, :integer
144
- t.column :rgt, :integer
195
+ t.column :parent_id, :integer
196
+ t.column :lft, :integer
197
+ t.column :rgt, :integer
145
198
  #custom columns go here
146
- t.column :description, :string
147
- t.column :comments, :string
148
- t.column :internal_identifier, :string
149
- t.column :external_identifier, :string
150
- t.column :external_id_source, :string
199
+ t.column :description, :string
200
+ t.column :comments, :string
201
+ t.column :internal_identifier, :string
202
+ t.column :external_identifier, :string
203
+ t.column :external_id_source, :string
151
204
  t.timestamps
152
205
  end
206
+
207
+ add_index :prod_instance_role_types, :parent_id, :name => "prod_type_role_types_parent_id_idx"
208
+ add_index :prod_instance_role_types, :lft, :name => "prod_type_role_types_lft_idx"
209
+ add_index :prod_instance_role_types, :rgt, :name => "prod_type_role_types_rgt_idx"
153
210
  end
154
-
211
+
212
+ # prod_type_relns
155
213
  unless table_exists?(:prod_type_relns)
156
214
  create_table :prod_type_relns do |t|
157
- t.column :prod_type_reln_type_id, :integer
158
- t.column :description, :string
159
- t.column :prod_type_id_from, :integer
160
- t.column :prod_type_id_to, :integer
161
- t.column :role_type_id_from, :integer
162
- t.column :role_type_id_to, :integer
163
- t.column :status_type_id, :integer
164
- t.column :from_date, :date
165
- t.column :thru_date, :date
166
- t.timestamps
167
- end
168
- end
169
-
170
- unless table_exists?(:product_instance_status_types)
171
- create_table :product_instance_status_types do |t|
172
- #better nested set colummns
173
- t.column :parent_id, :integer
174
- t.column :lft, :integer
175
- t.column :rgt, :integer
176
-
177
- t.column :description, :string
178
- t.column :internal_identifier, :string
179
- t.column :external_identifier, :string
180
- t.column :external_id_source, :string
181
-
182
- t.timestamps
183
- end
184
- end
185
-
186
- unless table_exists?(:prod_availability_status_types)
187
- create_table :prod_availability_status_types do |t|
188
- #better nested set colummns
189
- t.column :parent_id, :integer
190
- t.column :lft, :integer
191
- t.column :rgt, :integer
192
-
193
- t.column :description, :string
194
- t.column :internal_identifier, :string
195
- t.column :external_identifier, :string
196
- t.column :external_id_source, :string
197
-
215
+ t.column :prod_type_reln_type_id, :integer
216
+ t.column :description, :string
217
+ t.column :prod_type_id_from, :integer
218
+ t.column :prod_type_id_to, :integer
219
+ t.column :role_type_id_from, :integer
220
+ t.column :role_type_id_to, :integer
221
+ t.column :status_type_id, :integer
222
+ t.column :from_date, :date
223
+ t.column :thru_date, :date
198
224
  t.timestamps
199
225
  end
226
+
227
+ add_index :prod_type_relns, :prod_type_reln_type_id, :name => "prod_type_relns_type_idx"
228
+ add_index :prod_type_relns, :prod_type_id_from, :name => "prod_type_relns_type_from_idx"
229
+ add_index :prod_type_relns, :prod_type_id_to, :name => "prod_type_relns_type_to_idx"
230
+ add_index :prod_type_relns, :role_type_id_from, :name => "prod_type_relns_role_from_idx"
231
+ add_index :prod_type_relns, :role_type_id_to, :name => "prod_type_relns_role_to_idx"
200
232
  end
201
-
233
+
234
+ # prod_availability_status_types
202
235
  unless table_exists?(:prod_availability_status_types)
203
236
  create_table :prod_availability_status_types do |t|
204
237
  #better nested set colummns
205
238
  t.column :parent_id, :integer
206
- t.column :lft, :integer
207
- t.column :rgt, :integer
208
-
209
- t.column :description, :string
210
- t.column :internal_identifier, :string
211
- t.column :external_identifier, :string
212
- t.column :external_id_source, :string
213
-
239
+ t.column :lft, :integer
240
+ t.column :rgt, :integer
241
+
242
+ t.column :description, :string
243
+ t.column :internal_identifier, :string
244
+ t.column :external_identifier, :string
245
+ t.column :external_id_source, :string
246
+
214
247
  t.timestamps
215
248
  end
249
+
250
+ add_index :prod_availability_status_types, :parent_id, :name => "prod_avail_status_types_parent_id_idx"
251
+ add_index :prod_availability_status_types, :lft, :name => "prod_avail_status_types_lft_idx"
252
+ add_index :prod_availability_status_types, :rgt, :name => "prod_avail_status_types_rgt_idx"
216
253
  end
217
-
218
254
 
255
+ # product_type_pty_roles
256
+ unless table_exists?(:product_type_pty_roles)
257
+ create_table :product_type_pty_roles do |t|
258
+ t.references :party
259
+ t.references :role_type
260
+ t.references :product_type
261
+
262
+ t.timestamps
263
+ end
264
+
265
+ add_index :product_type_pty_roles, :party_id, :name => "product_type_pty_roles_party_idx"
266
+ add_index :product_type_pty_roles, :role_type_id, :name => "product_type_pty_roles_role_idx"
267
+ add_index :product_type_pty_roles, :product_type_id, :name => "product_type_pty_roles_prod_type_idx"
268
+ end
269
+
270
+ # product_features
271
+ unless table_exists?(:product_feature_types)
272
+ create_table :product_feature_types do |t|
273
+
274
+ t.integer :parent_id
275
+ t.integer :lft
276
+ t.integer :rgt
277
+
278
+ t.string :description
279
+ t.string :internal_identifier
280
+ t.string :external_identifier
281
+ t.string :external_id
282
+
283
+ t.timestamps
284
+ end
285
+ end
286
+
287
+ # product_feature_applicabilities
288
+ unless table_exists?(:product_feature_applicabilities)
289
+ create_table :product_feature_applicabilities do |t|
290
+ t.references :feature_of_record, :polymorphic => true
291
+ t.references :product_feature
292
+
293
+ t.boolean :is_mandatory
294
+
295
+ t.timestamps
296
+ end
297
+
298
+ add_index :product_feature_applicabilities, [:feature_of_record_type, :feature_of_record_id], :name => 'prod_feature_record_idx'
299
+ end
300
+
301
+ # product_feature_type_product_feature_values
302
+ unless table_exists?(:product_feature_type_product_feature_values)
303
+ create_table :product_feature_type_product_feature_values do |t|
304
+ t.references :product_feature_type
305
+ t.references :product_feature_value
306
+
307
+ t.timestamps
308
+ end
309
+
310
+ add_index :product_feature_type_product_feature_values, :product_feature_type_id, :name => 'prod_feature_type_feature_value_type_idx'
311
+ add_index :product_feature_type_product_feature_values, :product_feature_value_id, :name => 'prod_feature_type_feature_value_value_idx'
312
+ end
313
+
314
+ # product_features
315
+ unless table_exists?(:product_features)
316
+ create_table :product_features do |t|
317
+ t.references :product_feature_type
318
+ t.references :product_feature_value
319
+
320
+ t.timestamps
321
+ end
322
+
323
+ add_index :product_features, :product_feature_type_id, :name => 'prod_feature_type_idx'
324
+ add_index :product_features, :product_feature_value_id, :name => 'prod_feature_value_idx'
325
+ end
326
+
327
+ # product_feature_values
328
+ unless table_exists?(:product_feature_values)
329
+ create_table :product_feature_values do |t|
330
+ t.string :value
331
+ t.string :internal_identifier
332
+ t.string :external_identifier
333
+ t.string :external_id_source
334
+ t.string :description
335
+
336
+ t.timestamps
337
+ end
338
+ end
339
+
340
+ # product_feature_interactions
341
+ unless table_exists?(:product_feature_interactions)
342
+ create_table :product_feature_interactions do |t|
343
+ t.references :product_feature
344
+ t.references :interacted_product_feature
345
+ t.references :product_feature_interaction_type
346
+
347
+ t.timestamps
348
+ end
349
+
350
+ add_index :product_feature_interactions, :product_feature_id, :name => 'prod_feature_int_feature_idx'
351
+ add_index :product_feature_interactions, :interacted_product_feature_id, :name => 'prod_feature_int_interacted_feature_idx'
352
+ add_index :product_feature_interactions, :product_feature_interaction_type_id, :name => 'prod_feature_int_interacted_feature_type_idx'
353
+ end
354
+
355
+ # product_feature_interaction_types
356
+ unless table_exists?(:product_feature_interaction_types)
357
+ create_table :product_feature_interaction_types do |t|
358
+ t.string :internal_identifier
359
+ t.string :description
360
+
361
+ t.timestamps
362
+ end
363
+ end
219
364
  end
220
365
 
221
366
  def self.down
222
367
  [
223
- :prod_type_relns, :prod_type_role_types, :prod_type_reln_types,
224
- :prod_instance_relns, :prod_instance_role_types, :prod_instance_reln_types,
225
- :simple_product_offers, :product_offers, :product_instances,
226
- :product_types,:prod_availability_status_types
368
+ :prod_type_relns, :prod_type_role_types, :prod_type_reln_types,
369
+ :prod_instance_relns, :prod_instance_role_types, :prod_instance_reln_types,
370
+ :simple_product_offers, :product_offers, :product_instances,
371
+ :product_types, :prod_availability_status_types, :product_type_pty_roles,
372
+ :product_features, :product_feature_type_product_feature_values,
373
+ :product_feature_applicabilities, :product_features, :product_feature_values,
374
+ :product_feature_interactions, :product_feature_interaction_types
227
375
  ].each do |tbl|
228
376
  if table_exists?(tbl)
229
377
  drop_table tbl