Class: Supplier
- Inherits:
-
Party
- Object
- ActiveRecord::Base
- ApplicationRecord
- Party
- Supplier
- Includes:
- Models::Auditable, Models::LiquidMethods
- Defined in:
- app/models/supplier.rb
Overview
== Schema Information
Table name: parties
Database name: primary
id :integer not null, primary key
activities_count :integer default(0)
affiliations :text default([]), is an Array
annual_revenue :integer
authorization_code_required :boolean
available_credit :decimal(14, 2) default(0.0)
banner :text
best_time_to_call :string(255)
bill_shipping_to_customer :boolean
calculate_profiling :boolean default(FALSE), not null
can_pay_by_cod_business_check :boolean
consent_preferences :jsonb
contact_roles :string(255) is an Array
creation_method :integer default("crm"), not null
credit_limit :decimal(8, 2) default(0.0)
credit_score :integer
credit_score_date :datetime
currency :string(255)
default_payment_method :string
do_not_auto_assign :boolean default(FALSE), not null
dob :date
early_payment_discount :integer
early_payment_timescale :integer
estimated_landed_cost_ptg :float
force_logout :boolean default(FALSE), not null
full_name :string(255)
full_name_tsv :tsvector
gclid :string
gender :string(1)
inactive :boolean default(FALSE), not null
job_title :string(255)
lead_time :integer
lead_time_override :integer
lead_verification_score :integer
lead_verified_at :datetime
merged_from_ids :integer is an Array
name1 :string(255)
name2 :string(255)
name3 :string(255)
number_of_employees :integer
number_of_offices :string
on_hold :boolean default(FALSE), not null
on_hold_reason :text
open_sales_activity :boolean default(FALSE), not null
ordering_instructions :text
preferred_language :string
preferred_shipping_method :string(255)
prefix :string(10)
profile_info :text
projects_per_year :string
purchase_order_required :boolean default(FALSE), not null
qc_orders :boolean default(TRUE), not null
rating :string(255)
report_grouping :string(255)
requires_rma_reference :boolean
sales_priority_index :integer default(0)
send_statement :boolean default(FALSE), not null
send_statement_reason :string(255)
shipment_instructions :text
source_info :text
spiff_enrolled :boolean
state :string(255)
state_code :string(255)
suffix :string(10)
terms :string(255)
timezone_name :string
type :string(255)
uploads_count :integer default(0)
uuid :uuid not null
verbal_po :boolean default(FALSE), not null
watch :integer
created_at :datetime
updated_at :datetime
active_spiff_enrollment_id :integer
billing_address_id :integer
bot_id :string
business_unit_id :integer
buying_group_id :integer
catalog_id :integer
company_id :integer
creator_id :integer
customer_id :integer
gl_offset_account_id :integer
ledger_detail_project_id :integer
legacy_tier2_program_pricing_id :integer
local_sales_rep_id :integer
mailing_address_id :integer
original_source_id :integer
parent_id :integer
paypal_vault_customer_id :string
paypal_vault_token_id :string
primary_sales_rep_id :integer
profile_id :integer
profile_image_id :integer
secondary_sales_rep_id :integer
service_rep_id :integer
shipping_address_id :integer
source_id :integer
spiff_address_id :integer
spiff_payable_id :integer
stripe_customer_id :string
tier2_program_pricing_id :integer
updater_id :integer
visit_id :bigint
Indexes
idx_parties_full_name_trg (full_name) USING gin
idx_party_main_address (COALESCE(shipping_address_id, billing_address_id, mailing_address_id))
idx_state_type (state,type)
idx_type_billing_address_id (type,billing_address_id)
idx_type_creation_method_state (type,creation_method,state)
idx_type_customer_id (type,customer_id)
idx_type_id_credit_limit (type,id,credit_limit)
idx_type_inactive (type,inactive)
idx_type_primary_sales_rep_id_watch (type,primary_sales_rep_id,watch)
index_parties_on_affiliations (affiliations) USING gin
index_parties_on_billing_address_id (billing_address_id)
index_parties_on_bot_id (bot_id) WHERE (bot_id IS NOT NULL)
index_parties_on_catalog_id (catalog_id)
index_parties_on_company_id (company_id)
index_parties_on_full_name_tsv (full_name_tsv) USING gin
index_parties_on_gclid (gclid) WHERE (gclid IS NOT NULL)
index_parties_on_local_sales_rep_id (local_sales_rep_id)
index_parties_on_mailing_address_id (mailing_address_id)
index_parties_on_merged_from_ids (merged_from_ids) USING gin
index_parties_on_open_sales_activity (open_sales_activity)
index_parties_on_parent_id (parent_id)
index_parties_on_primary_sales_rep_id (primary_sales_rep_id)
index_parties_on_profile_image_id (profile_image_id) USING hash
index_parties_on_report_grouping (report_grouping)
index_parties_on_secondary_sales_rep_id (secondary_sales_rep_id)
index_parties_on_service_rep_id (service_rep_id)
index_parties_on_source_id (source_id)
index_parties_on_tier2_program_pricing_id (tier2_program_pricing_id)
index_parties_on_uuid (uuid) UNIQUE
index_parties_on_visit_id (visit_id) WHERE (visit_id IS NOT NULL) USING hash
index_parties_on_watch (watch)
parties_buying_group_id_idx (buying_group_id)
parties_customer_id_index (customer_id)
parties_profile_id_idx (profile_id)
parties_shipping_address_id_idx (shipping_address_id)
parties_spiff_address_id_idx (spiff_address_id)
parties_spiff_payable_id_idx (spiff_payable_id)
Foreign Keys
fk_rails_... (profile_image_id => digital_assets.id) ON DELETE => nullify
fk_rails_... (source_id => sources.id)
fk_rails_... (visit_id => visits.id) ON DELETE => nullify
parties_billing_address_id_fk (billing_address_id => addresses.id) ON DELETE => nullify
parties_buying_group_id_fk (buying_group_id => buying_groups.id)
parties_catalog_id_fk (catalog_id => catalogs.id)
parties_company_id_fk (company_id => companies.id)
parties_customer_id_fk (customer_id => parties.id) ON DELETE => cascade
parties_mailing_address_id_fk (mailing_address_id => addresses.id) ON DELETE => nullify
parties_parent_id_fk (parent_id => parties.id) ON DELETE => nullify
parties_primary_sales_rep_id_fk (primary_sales_rep_id => parties.id) ON DELETE => nullify
parties_profile_id_fk (profile_id => profiles.id)
parties_secondary_sales_rep_id_fk (secondary_sales_rep_id => parties.id) ON DELETE => nullify
parties_shipping_address_id_fk (shipping_address_id => addresses.id) ON DELETE => nullify
parties_source_id_fk (source_id => sources.id)
parties_spiff_address_id_fk (spiff_address_id => addresses.id) ON DELETE => nullify
parties_spiff_payable_id_fk (spiff_payable_id => parties.id) ON DELETE => nullify
parties_tier2_program_pricing_id_fk (tier2_program_pricing_id => coupons.id)
Vendor / supplier party (parties.type = Supplier) used in purchasing, POs,
and item lead-time forecasting.
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants inherited from Party
Instance Attribute Summary collapse
- #currency ⇒ Object readonly
- #full_name ⇒ Object readonly
- #terms ⇒ Object readonly
Attributes inherited from Party
Belongs to collapse
- #billing_address ⇒ Address
- #business_unit ⇒ BusinessUnit
- #mailing_address ⇒ Address
- #shipping_address ⇒ Address
Methods included from Models::Auditable
Methods inherited from Party
#catalog, #company, #customer, #gl_offset_account, #profile_image, #visit
Has many collapse
- #budgets ⇒ ActiveRecord::Relation<Budget>
- #supplier_items ⇒ ActiveRecord::Relation<SupplierItem>
- #view_estimated_landed_costs ⇒ ActiveRecord::Relation<ViewEstimatedLandedCost>
Methods inherited from Party
#accounts, #activities, #addresses, #agreement_participants, #agreements, #assistant_conversations, #billing_credit_memos, #consignment_stores, #contact_points, #contacts, #course_enrollments, #credit_memos, #destination_call_logs, #destination_call_records, #inbound_communications, #notifications, #opportunity_participants, #origin_call_logs, #origin_call_records, #outbound_communications, #outgoing_payments, #party_topics, #purchase_orders, #queue_call_logs, #receipts, #recipient_sms_messages, #room_plans, #sender_sms_messages, #support_case_participants, #support_cases, #survey_enrollments, #uploads, #visit_events, #visits, #voucher_items, #vouchers
Has one collapse
Methods inherited from Party
Class Method Summary collapse
-
.options_for_select ⇒ Array<Array(String, Integer)>
Active suppliers for select lists (
[name, id]pairs).
Instance Method Summary collapse
-
#calculate_lead_time ⇒ void
Recomputes #lead_time from recent ViewLeadTime averages (or domestic default).
-
#currency_symbol ⇒ String
ISO currency symbol for #currency.
-
#estimated_landed_cost? ⇒ Boolean
Whether landed-cost percentage is present on the record.
-
#resources_for_select(options = {}) ⇒ Object
Activity resources available for this supplier (same helper as Contact#resources_for_select).
-
#supplier ⇒ Supplier
Self-reference for polymorphic call sites that expect
#supplier.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from Party
#can?, #cannot?, #digital_assets, #has_role?, #is_admin?, #is_document_maintainer?, #is_local_sales_rep?, #is_manager?, #is_marketing_manager?, #is_sales_manager?, #is_sales_rep?, #linked_activities, #locale, #main_address, #product_lines, #set_full_name, #set_state_code, #set_timezone
Methods included from CrmLinkable
#crm_link, #crm_link_with_host
Methods included from PartyAccount
#ability, #build_account, #create_account, #online_account_invite, #refuse_silent_account_replacement!, search_for_authenticable_linked_party_by_email
Methods included from PartyCart
#all_uploads, #assign_chained_activities?, #cart, #cart=, #cart?, #cart_id, #cart_info, #create_activity, #create_quote_builder_project, #load_cart, #store_original_source
Methods included from PartyIdentity
#active?, #admin?, #aka, #aka=, #all_activities, #blog_admin?, #broadcast_product_interest_changed, #can_be_certified?, #can_list_all_contact_resources?, #clear_individual_names, #clear_names, #contact?, #customer?, #determine_company_id, #direct_commercial?, #direct_pro?, #employee?, #first_name, #first_name=, #guest_individual_name?, #guest_name?, #homeowner?, #id_and_name, #last_name, #last_name=, #manager?, #middle_name, #middle_name=, #name, #name=, #organization?, #person?, #primary_party, #public_facing_full_name, #public_facing_full_name=, #show_name_four, #to_s, #update_product_interests
Methods included from PartyAddresses
#addresses_options_for_select, #can_change_country?, #catalog_country, #catalog_country_iso, #catalog_country_iso3, #city, #country, #country_iso, #country_iso3, #first_address, #flag, #location_name, #most_recent_visit, #new_address, #store, #street1, #street2, #street3, #timezone, #unique_addresses, #visit_data, #visit_location, #zip
Methods included from PartyContactInfo
#all_support_cases, #call_records?, #cell_phone, #cell_phone=, #cell_phone_formatted, #contact_point_options_for_select, #contactable?, #email, #email=, #email_options_for_select, #email_with_name, #emails, #fax, #fax=, #fax_formatted, #fax_options_for_select, #first_callable_contact_point, #first_contact_point_by_category, #phone, #phone=, #phone_formatted, #phone_options_for_select, #set_email_from_account, #set_primary_contact_point, #sms_enabled_numbers, #sms_messages, #tracking_email_address, #tracking_email_prefix, #website, #website=, #website_options_for_select
Methods included from PartySearch
active, address_search, customer_or_contact, email_search, inactive, lookup, phone_search, ransackable_scopes, searchable, with_main_address
Methods included from Models::Notable
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#currency ⇒ Object (readonly)
192 |
# File 'app/models/supplier.rb', line 192 validates :full_name, :terms, :currency, presence: true |
#full_name ⇒ Object (readonly)
192 |
# File 'app/models/supplier.rb', line 192 validates :full_name, :terms, :currency, presence: true |
#terms ⇒ Object (readonly)
192 |
# File 'app/models/supplier.rb', line 192 validates :full_name, :terms, :currency, presence: true |
Class Method Details
.options_for_select ⇒ Array<Array(String, Integer)>
Active suppliers for select lists ([name, id] pairs).
226 227 228 |
# File 'app/models/supplier.rb', line 226 def self. where(state: :active).order(:full_name).pluck(:full_name, :id) end |
Instance Method Details
#billing_address ⇒ Address
183 |
# File 'app/models/supplier.rb', line 183 belongs_to :billing_address, class_name: 'Address', validate: false, optional: true |
#budgets ⇒ ActiveRecord::Relation<Budget>
187 |
# File 'app/models/supplier.rb', line 187 has_many :budgets, dependent: :destroy |
#business_unit ⇒ BusinessUnit
181 |
# File 'app/models/supplier.rb', line 181 belongs_to :business_unit, optional: true |
#calculate_lead_time ⇒ void
This method returns an undefined value.
Recomputes #lead_time from recent ViewLeadTime averages (or domestic default).
247 248 249 250 251 |
# File 'app/models/supplier.rb', line 247 def calculate_lead_time times = fetch_avg_lead_times max_lt = times.empty? ? default_lead_time : times.max.round update!(lead_time: max_lt) end |
#currency_symbol ⇒ String
ISO currency symbol for #currency.
219 220 221 |
# File 'app/models/supplier.rb', line 219 def currency_symbol Money::Currency.new(currency).symbol end |
#estimated_landed_cost? ⇒ Boolean
Whether landed-cost percentage is present on the record.
240 241 242 |
# File 'app/models/supplier.rb', line 240 def estimated_landed_cost? estimated_landed_cost_ptg.present? end |
#mailing_address ⇒ Address
184 |
# File 'app/models/supplier.rb', line 184 belongs_to :mailing_address, class_name: 'Address', validate: false, optional: true |
#resources_for_select(options = {}) ⇒ Object
Activity resources available for this supplier (same helper as Contact#resources_for_select).
212 213 214 |
# File 'app/models/supplier.rb', line 212 def resources_for_select( = {}) Activity::ResourceList.new.process(self, ) end |
#shipping_address ⇒ Address
182 |
# File 'app/models/supplier.rb', line 182 belongs_to :shipping_address, class_name: 'Address', validate: false, optional: true |
#supplier ⇒ Supplier
Self-reference for polymorphic call sites that expect #supplier.
233 234 235 |
# File 'app/models/supplier.rb', line 233 def supplier self end |
#supplier_items ⇒ ActiveRecord::Relation<SupplierItem>
186 |
# File 'app/models/supplier.rb', line 186 has_many :supplier_items, dependent: :destroy |
#view_estimated_landed_cost ⇒ ViewEstimatedLandedCost
190 |
# File 'app/models/supplier.rb', line 190 has_one :view_estimated_landed_cost, class_name: 'ViewEstimatedLandedCost', dependent: :destroy |
#view_estimated_landed_costs ⇒ ActiveRecord::Relation<ViewEstimatedLandedCost>
188 |
# File 'app/models/supplier.rb', line 188 has_many :view_estimated_landed_costs, dependent: :destroy |