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
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
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
- #dealer? ⇒ Boolean
- #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
-
#trade_pro? ⇒ Boolean
Trade-Pro and Dealer membership are encoded in the profile name prefix ("TP - …", "DL - …", "HO - …" — same convention used by
Profile.trade_proscope andProfile#homeowner?).
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#name ⇒ Object (readonly)
44 |
# File 'app/models/profile.rb', line 44 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
42 |
# File 'app/models/profile.rb', line 42 scope :active, -> { where(active: true) } |
.exclude_admin_options ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are exclude admin options. Active Record Scope
39 |
# File 'app/models/profile.rb', line 39 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
40 |
# File 'app/models/profile.rb', line 40 scope :exclude_homeowner, -> { where.not("name LIKE 'HO %'") } |
.homeowner ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are homeowner. Active Record Scope
41 |
# File 'app/models/profile.rb', line 41 scope :homeowner, -> { where(id: ProfileConstants::HOMEOWNER) } |
.homeowner_profile ⇒ Object
46 47 48 |
# File 'app/models/profile.rb', line 46 def self.homeowner_profile Profile.find(ProfileConstants::HOMEOWNER) end |
.options_for_select(admin = false, friendly_name = false, exclude_homeowner = false, include_description = false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/profile.rb', line 54 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
38 |
# File 'app/models/profile.rb', line 38 scope :trade_pro, -> { where("name LIKE 'TP %'") } |
.trades ⇒ ActiveRecord::Relation<Profile>
A relation of Profiles that are trades. Active Record Scope
37 |
# File 'app/models/profile.rb', line 37 scope :trades, -> { exclude_homeowner. } |
.unknown_trade ⇒ Object
50 51 52 |
# File 'app/models/profile.rb', line 50 def self.unknown_trade Profile.find(ProfileConstants::UNKNOWN_TRADE) end |
Instance Method Details
#correct_discount(number_of_completed_orders) ⇒ Object
130 131 132 133 134 135 136 |
# File 'app/models/profile.rb', line 130 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>
34 |
# File 'app/models/profile.rb', line 34 has_many :customers |
#dealer? ⇒ Boolean
102 103 104 |
# File 'app/models/profile.rb', line 102 def dealer? name.to_s.start_with?('DL ') end |
#direct_commercial? ⇒ Boolean
122 123 124 |
# File 'app/models/profile.rb', line 122 def direct_commercial? report_grouping == 'Direct - Commercial Sales' end |
#direct_pro? ⇒ Boolean
def distributor?
report_grouping == 'Wholesalers'
end
118 119 120 |
# File 'app/models/profile.rb', line 118 def direct_pro? report_grouping == 'Direct - PRO' end |
#e_commerce_misc? ⇒ Boolean
126 127 128 |
# File 'app/models/profile.rb', line 126 def e_commerce_misc? report_grouping == 'E-commerce - Misc' end |
#friendly_name ⇒ Object
78 79 80 81 82 |
# File 'app/models/profile.rb', line 78 def friendly_name fn = name[/.{1,3} - (.*)/, 1] fn = name if fn.nil? fn end |
#homeowner? ⇒ Boolean
88 89 90 |
# File 'app/models/profile.rb', line 88 def homeowner? id == ProfileConstants::HOMEOWNER end |
#invoices ⇒ ActiveRecord::Relation<Invoice>
35 |
# File 'app/models/profile.rb', line 35 has_many :invoices |
#organization? ⇒ Boolean
84 85 86 |
# File 'app/models/profile.rb', line 84 def organization? !homeowner? end |
#tier2_program_pricing ⇒ Coupon::Tier2ProgramPricing
32 |
# File 'app/models/profile.rb', line 32 belongs_to :tier2_program_pricing, class_name: 'Coupon::Tier2ProgramPricing', optional: true |
#to_s ⇒ Object
106 107 108 |
# File 'app/models/profile.rb', line 106 def to_s name end |
#trade_pro? ⇒ Boolean
Trade-Pro and Dealer membership are encoded in the profile name prefix
("TP - …", "DL - …", "HO - …" — same convention used by Profile.trade_pro
scope and Profile#homeowner?). The previous canonical check at
Customer#dealer_or_trade_pro_for_locator? read profile.jde_code_1,
which is a legacy attribute being phased out — these predicates
replace that path.
98 99 100 |
# File 'app/models/profile.rb', line 98 def trade_pro? name.to_s.start_with?('TP ') end |