Class: ProductType
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- ProductType
- Includes:
- ErpTechSvcs::Utils::DefaultNestedSetMethods
- Defined in:
- app/models/product_type.rb
Overview
create_table :product_types do |t|
#these columns are required to support the behavior of the plugin 'better_nested_set'
#ALL products have the ability to act as packages in a nested set-type structure
#
#The package behavior is treated differently from other product_relationship behavior
#which is implemented using a standard relationship structure.
#
#This is to allow quick construction of highly nested product types.
t.column :parent_id, :integer
t.column :lft, :integer
t.column :rgt, :integer
#custom columns go here
t.column :description, :string
t.column :product_type_record_id, :integer
t.column :product_type_record_type, :string
t.column :external_identifier, :string
t.column :internal_identifier, :string
t.column :external_id_source, :string
t.column :default_image_url, :string
t.column :list_view_image_id, :integer
t.column :length, :decimal
t.column :width, :decimal
t.column :height, :decimal
t.column :weight, :decimal
t.column :cylindrical, :boolean
t.column :taxable :boolean
t.column :available_on_web :boolean
t.references :unit_of_measurement
t.references :biz_txn_acct_root
t.timestamps
end
add_index :product_types, :biz_txn_acct_root_id
Class Method Summary collapse
-
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records.
- .count_by_status(product_type, prod_availability_status_type) ⇒ Object
-
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation
scope by dba organization.
-
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party.
Instance Method Summary collapse
-
#add_party_with_role(party, role_type) ⇒ ProductTypePtyRole
add party with passed role to this ProductType.
- #add_party_with_role_type(party, role_type) ⇒ Object
- #has_dimensions? ⇒ Boolean
- #images_path ⇒ Object
- #parent_dba_organizations(dba_orgs = []) ⇒ Object
- #prod_type_relns_from ⇒ Object
- #prod_type_relns_to ⇒ Object
- #taxable? ⇒ Boolean
- #to_data_hash ⇒ Object
- #to_display_hash ⇒ Object
- #to_label ⇒ Object
- #to_s ⇒ Object
Class Method Details
.apply_filters(filters, statement = nil) ⇒ ActiveRecord::Relation
Filter records
67 68 69 70 71 72 73 |
# File 'app/models/product_type.rb', line 67 def apply_filters(filters, statement=nil) unless statement statement = ProductType end statement end |
.count_by_status(product_type, prod_availability_status_type) ⇒ Object
140 141 142 |
# File 'app/models/product_type.rb', line 140 def self.count_by_status(product_type, prod_availability_status_type) ProductInstance.count("product_type_id = #{product_type.id} and prod_availability_status_type_id = #{prod_availability_status_type.id}") end |
.scope_by_dba_organization(dba_organization) ⇒ ActiveRecord::Relation
scope by dba organization
84 85 86 |
# File 'app/models/product_type.rb', line 84 def scope_by_dba_organization(dba_organization) scope_by_party(dba_organization, {role_types: [RoleType.iid('dba_org')]}) end |
.scope_by_party(party, options = {}) ⇒ ActiveRecord::Relation
scope by party
or an array of Party ids
96 97 98 99 100 101 102 103 104 |
# File 'app/models/product_type.rb', line 96 def scope_by_party(party, ={}) statement = joins(:product_type_pty_roles).where("product_type_pty_roles.party_id" => party).uniq if [:role_types] statement = statement.where("product_type_pty_roles.role_type_id" => RoleType.find_child_role_types([:role_types])) end statement end |
Instance Method Details
#add_party_with_role(party, role_type) ⇒ ProductTypePtyRole
add party with passed role to this ProductType
112 113 114 115 116 117 118 |
# File 'app/models/product_type.rb', line 112 def add_party_with_role(party, role_type) ProductTypePtyRole.create( product_type: self, party: party, role_type: role_type ) end |
#add_party_with_role_type(party, role_type) ⇒ Object
188 189 190 191 192 193 194 |
# File 'app/models/product_type.rb', line 188 def add_party_with_role_type(party, role_type) if role_type.is_a?(String) role_type = RoleType.iid(role_type) end ProductTypePtyRole.create(party: party, role_type: role_type, product_type: self) end |
#has_dimensions? ⇒ Boolean
196 197 198 |
# File 'app/models/product_type.rb', line 196 def has_dimensions? (cylindrical && length && width && weight) or (length && width && height && weight) end |
#images_path ⇒ Object
144 145 146 147 |
# File 'app/models/product_type.rb', line 144 def images_path file_support = ErpTechSvcs::FileSupport::Base.new(:storage => Rails.application.config.erp_tech_svcs.file_storage) File.join(file_support.root, Rails.application.config.erp_tech_svcs.file_assets_location, 'products', 'images', "#{self.description.underscore}_#{self.id}") end |
#parent_dba_organizations(dba_orgs = []) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 |
# File 'app/models/product_type.rb', line 176 def parent_dba_organizations(dba_orgs=[]) ProductTypePtyRole. where('product_type_id = ?', id). where('role_type_id' => RoleType.iid('dba_org').id).each do |prod_party_reln| dba_orgs.push(prod_party_reln.party) prod_party_reln.party.parent_dba_organizations(dba_orgs) end dba_orgs.uniq end |
#prod_type_relns_from ⇒ Object
128 129 130 |
# File 'app/models/product_type.rb', line 128 def prod_type_relns_from ProdTypeReln.where('prod_type_id_from = ?', id) end |
#prod_type_relns_to ⇒ Object
124 125 126 |
# File 'app/models/product_type.rb', line 124 def prod_type_relns_to ProdTypeReln.where('prod_type_id_to = ?', id) end |
#taxable? ⇒ Boolean
120 121 122 |
# File 'app/models/product_type.rb', line 120 def taxable? self.taxable end |
#to_data_hash ⇒ Object
149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'app/models/product_type.rb', line 149 def to_data_hash to_hash(only: [ :id, :description, :internal_identifier, :sku, :comment, :created_at, :updated_at ], unit_of_measurement: try(:unit_of_measurement).try(:to_data_hash), price: try(:get_current_simple_plan).try(:money_amount), gl_account: try(:gl_account).try(:to_data_hash)) end |
#to_display_hash ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 |
# File 'app/models/product_type.rb', line 164 def to_display_hash { id: id, description: description, offer_list_description: find_descriptions_by_view_type('list_description').first.try(:description), offer_short_description: find_descriptions_by_view_type('short_description').first.try(:description), offer_long_description: find_descriptions_by_view_type('long_description').first.try(:description), offer_base_price: get_current_simple_amount_with_currency, images: images.pluck(:id) } end |
#to_label ⇒ Object
132 133 134 |
# File 'app/models/product_type.rb', line 132 def to_label "#{description}" end |
#to_s ⇒ Object
136 137 138 |
# File 'app/models/product_type.rb', line 136 def to_s "#{description}" end |