Class: Profile
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Profile
- Includes:
- Models::Auditable
- Defined in:
- app/models/profile.rb
Overview
== Schema Information
Table name: profiles
Database name: primary
id :integer not null, primary key
active :boolean default(TRUE), not null
description :text
jde_code_1 :string(255)
jde_code_1_bg :string(255)
jde_code_2 :string(255)
locator_eligible :boolean default(FALSE), not null
name :string(255)
report_grouping :string(255)
created_at :datetime
updated_at :datetime
legacy_tier2_program_pricing_id :integer
tier2_program_pricing_id :integer
Indexes
profiles_tier2_program_pricing_id_idx (tier2_program_pricing_id)
Foreign Keys
profiles_tier2_program_pricing_id_fk (tier2_program_pricing_id => coupons.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
- #name ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are active.
-
.exclude_admin_options ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are exclude admin options.
-
.exclude_homeowner ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are exclude homeowner.
-
.homeowner ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are homeowner.
- .homeowner_profile ⇒ Object
- .options_for_select(admin = false, friendly_name = false, exclude_homeowner = false, include_description = false) ⇒ Object
-
.trade_pro ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are trade pro.
-
.trades ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are trades.
- .unknown_trade ⇒ Object
Instance Method Summary collapse
- #correct_discount(number_of_completed_orders) ⇒ Object
- #direct_commercial? ⇒ Boolean
-
#direct_pro? ⇒ Boolean
def distributor? report_grouping == 'Wholesalers' end.
- #e_commerce_misc? ⇒ Boolean
- #friendly_name ⇒ Object
- #homeowner? ⇒ Boolean
- #organization? ⇒ Boolean
- #to_s ⇒ Object
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ Object (readonly)
43 |
# File 'app/models/profile.rb', line 43 validates :name, presence: true, uniqueness: { case_sensitive: false } |
Class Method Details
.active ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are active. Active Record Scope
41 |
# File 'app/models/profile.rb', line 41 scope :active, -> { where(active: true) } |
.exclude_admin_options ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are exclude admin options. Active Record Scope
38 |
# File 'app/models/profile.rb', line 38 scope :exclude_admin_options, -> { where.not("name ILIKE 'Buying Group'") } |
.exclude_homeowner ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are exclude homeowner. Active Record Scope
39 |
# File 'app/models/profile.rb', line 39 scope :exclude_homeowner, -> { where.not("name LIKE 'HO %'") } |
.homeowner ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are homeowner. Active Record Scope
40 |
# File 'app/models/profile.rb', line 40 scope :homeowner, -> { where(id: ProfileConstants::HOMEOWNER) } |
.homeowner_profile ⇒ Object
45 46 47 |
# File 'app/models/profile.rb', line 45 def self.homeowner_profile Profile.find(ProfileConstants::HOMEOWNER) end |
.options_for_select(admin = false, friendly_name = false, exclude_homeowner = false, include_description = false) ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/profile.rb', line 53 def self.(admin = false, friendly_name = false, exclude_homeowner = false, include_description = false) profiles = Profile.active.order(:name) profiles = profiles. unless admin profiles = profiles.exclude_homeowner if exclude_homeowner profiles.map do |p| dn = if friendly_name if p.name == 'TP - Architect' 'Architect Professional' elsif p.name == 'DL - Architect' 'Architect Dealer' else p.friendly_name end else p.name end if include_description [dn, p.id, { description: p.name }] else [dn, p.id] end end.sort_by { |pe| pe[0] } end |
.trade_pro ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are trade pro. Active Record Scope
37 |
# File 'app/models/profile.rb', line 37 scope :trade_pro, -> { where("name LIKE 'TP %'") } |
.trades ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are trades. Active Record Scope
36 |
# File 'app/models/profile.rb', line 36 scope :trades, -> { exclude_homeowner. } |
.unknown_trade ⇒ Object
49 50 51 |
# File 'app/models/profile.rb', line 49 def self.unknown_trade Profile.find(ProfileConstants::UNKNOWN_TRADE) end |
Instance Method Details
#correct_discount(number_of_completed_orders) ⇒ Object
123 124 125 126 127 128 129 |
# File 'app/models/profile.rb', line 123 def correct_discount(number_of_completed_orders) if number_of_completed_orders >= pricing_programs.length pricing_programs.to_a.last else pricing_programs.to_a[number_of_completed_orders] end end |
#customers ⇒ ActiveRecord::Relation<Customer>
33 |
# File 'app/models/profile.rb', line 33 has_many :customers |
#direct_commercial? ⇒ Boolean
115 116 117 |
# File 'app/models/profile.rb', line 115 def direct_commercial? report_grouping == 'Direct - Commercial Sales' end |
#direct_pro? ⇒ Boolean
def distributor?
report_grouping == 'Wholesalers'
end
111 112 113 |
# File 'app/models/profile.rb', line 111 def direct_pro? report_grouping == 'Direct - PRO' end |
#e_commerce_misc? ⇒ Boolean
119 120 121 |
# File 'app/models/profile.rb', line 119 def e_commerce_misc? report_grouping == 'E-commerce - Misc' end |
#friendly_name ⇒ Object
77 78 79 80 81 |
# File 'app/models/profile.rb', line 77 def friendly_name fn = name[/.{1,3} - (.*)/, 1] fn = name if fn.nil? fn end |
#homeowner? ⇒ Boolean
87 88 89 |
# File 'app/models/profile.rb', line 87 def homeowner? id == ProfileConstants::HOMEOWNER end |
#invoices ⇒ ActiveRecord::Relation<Invoice>
34 |
# File 'app/models/profile.rb', line 34 has_many :invoices |
#organization? ⇒ Boolean
83 84 85 |
# File 'app/models/profile.rb', line 83 def organization? !homeowner? end |
#tier2_program_pricing ⇒ Coupon::Tier2ProgramPricing
31 |
# File 'app/models/profile.rb', line 31 belongs_to :tier2_program_pricing, class_name: 'Coupon::Tier2ProgramPricing', optional: true |
#to_s ⇒ Object
91 92 93 |
# File 'app/models/profile.rb', line 91 def to_s name end |