Class: CustomerDropEvent

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/customer_drop_event.rb

Overview

== Schema Information

Table name: customer_drop_events
Database name: primary

id :integer not null, primary key
comment :text
reason_code :string(255)
created_at :datetime
updated_at :datetime
creator_id :integer
customer_id :integer not null
sales_rep_id :integer
updater_id :integer

Indexes

index_customer_drop_events_on_customer_id (customer_id)

Constant Summary collapse

CLOSING_CONDITIONS =
%w[disconnected_number no_longer_in_business fraud].freeze
REASON_CODES =
(CLOSING_CONDITIONS + %w[no_potential not_related_to_our_business reassign_account]).freeze

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

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

#publish_event

Instance Attribute Details

#reason_codeObject (readonly)



29
# File 'app/models/customer_drop_event.rb', line 29

validates :customer, :reason_code, presence: true

Class Method Details

.closing_condition?(reason_code) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/models/customer_drop_event.rb', line 40

def self.closing_condition?(reason_code)
  CLOSING_CONDITIONS.include?(reason_code)
end

.human_reason_name(reason) ⇒ Object



48
49
50
51
52
# File 'app/models/customer_drop_event.rb', line 48

def self.human_reason_name(reason)
  r = { 'fraud' => 'Fraud or Spam' }[reason] || reason.dup.humanize.titleize
  r << ' (Close Account)' if reason.in?(CLOSING_CONDITIONS)
  r
end

.options_for_selectObject



54
55
56
# File 'app/models/customer_drop_event.rb', line 54

def self.options_for_select
  REASON_CODES.map { |r| [human_reason_name(r), r] }
end

Instance Method Details

#closing_condition?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'app/models/customer_drop_event.rb', line 32

def closing_condition?
  self.class.closing_condition?(reason_code)
end

#customerCustomer

Returns:

See Also:

Validations:



26
# File 'app/models/customer_drop_event.rb', line 26

belongs_to :customer, optional: true

#reassign_rep?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'app/models/customer_drop_event.rb', line 36

def reassign_rep?
  reason_code == 'reassign_account'
end

#sales_repEmployee

Returns:

See Also:



27
# File 'app/models/customer_drop_event.rb', line 27

belongs_to :sales_rep, class_name: 'Employee', optional: true

#spam_condition?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/models/customer_drop_event.rb', line 44

def spam_condition?
  reason_code == 'fraud'
end