Class: NotificationChannel

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

Overview

== Schema Information

Table name: notification_channels
Database name: primary

id :integer not null, primary key
fallback_for_subsidiaries :boolean default(TRUE), not null
notification_type :string not null
transmission_type :string(255)
created_at :datetime
updated_at :datetime
contact_point_id :integer
customer_id :integer not null

Indexes

index_notification_channel_unique (customer_id, contact_point_id, notification_type, COALESCE(transmission_type, ''::character varying)) UNIQUE
index_notification_channels_on_contact_point_id (contact_point_id)
index_notification_channels_on_customer_id (customer_id)

Foreign Keys

notification_channels_contact_point_id_fk (contact_point_id => contact_points.id) ON DELETE => cascade
notification_channels_customer_id_fkey (customer_id => parties.id)

Constant Summary collapse

ORDERS_SHIPMENT =
'ORS'
INVOICES =
'invoices'
RMA =
'RMA'
CREDIT_MEMOS =
'credit_memos'
STATEMENT_OF_ACCOUNTS =
'statement_of_accounts'
EMAIL_OR_FAX =
'Email/Fax'
MAIL =
'Mail'
PORTAL =
'Portal'
EDI =
'EDI'
NOTIFICATION_TYPES =
{'Order Shipment Notifications': ORDERS_SHIPMENT,
'Invoices': INVOICES,
'RMA': RMA,
'Credit Memos': CREDIT_MEMOS,
'Statement of Accounts': STATEMENT_OF_ACCOUNTS}
TRANSMISSION_TYPES =
[EMAIL_OR_FAX, MAIL, PORTAL, EDI]

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

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

Class Method Details

.contact_points_for_select(customer) ⇒ Object



105
106
107
108
# File 'app/models/notification_channel.rb', line 105

def self.contact_points_for_select(customer)
  party_ids = customer.all_my_active_party_ids + [87] #Venu, harcoded
  ContactPoint.includes(:party).where(party_id: party_ids).map{|cp| ["#{cp.party.full_name} : #{cp.detail}", cp.id] }
end

.credit_memosActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are credit memos. Active Record Scope

Returns:

See Also:



93
# File 'app/models/notification_channel.rb', line 93

scope :credit_memos, -> { where(notification_type: CREDIT_MEMOS) }

.emailActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are email. Active Record Scope

Returns:

See Also:



91
# File 'app/models/notification_channel.rb', line 91

scope :email, -> { eager_load(:contact_point).merge(ContactPoint.emails) }

.fallback_enabledActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are fallback enabled. Active Record Scope

Returns:

See Also:



94
# File 'app/models/notification_channel.rb', line 94

scope :fallback_enabled, -> { where(fallback_for_subsidiaries: true) }

.faxActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are fax. Active Record Scope

Returns:

See Also:



92
# File 'app/models/notification_channel.rb', line 92

scope :fax, -> { eager_load(:contact_point).merge(ContactPoint.faxes) }

.for_customerActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are for customer. Active Record Scope

Returns:

See Also:



95
# File 'app/models/notification_channel.rb', line 95

scope :for_customer, ->(customer) { where(customer_id: customer.id).or(fallback_enabled.where(NotificationChannel[:customer_id].gt(0)).where(customer_id: customer.parent_id.to_i)) }

.invoicesActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are invoices. Active Record Scope

Returns:

See Also:



89
# File 'app/models/notification_channel.rb', line 89

scope :invoices, -> { where(notification_type: INVOICES) }

.notification_types_for_selectObject



97
98
99
# File 'app/models/notification_channel.rb', line 97

def self.notification_types_for_select
  NotificationChannel::NOTIFICATION_TYPES.collect {|k,v| [k,v]}
end

.orders_shipmentActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are orders shipment. Active Record Scope

Returns:

See Also:



88
# File 'app/models/notification_channel.rb', line 88

scope :orders_shipment, -> { where(notification_type: ORDERS_SHIPMENT) }

.rmasActiveRecord::Relation<NotificationChannel>

A relation of NotificationChannels that are rmas. Active Record Scope

Returns:

See Also:



90
# File 'app/models/notification_channel.rb', line 90

scope :rmas, -> { where(notification_type: NotificationChannel::RMA) }

.transmission_types_for_selectObject



101
102
103
# File 'app/models/notification_channel.rb', line 101

def self.transmission_types_for_select
  NotificationChannel::TRANSMISSION_TYPES.collect {|tt| [tt,tt]}
end

Instance Method Details

#clear_contact_point_idObject



122
123
124
# File 'app/models/notification_channel.rb', line 122

def clear_contact_point_id
  self.contact_point_id = nil
end

#contact_pointContactPoint



77
# File 'app/models/notification_channel.rb', line 77

belongs_to :contact_point, optional: true

#contact_point_is_transmittableObject



114
115
116
# File 'app/models/notification_channel.rb', line 114

def contact_point_is_transmittable
  errors[:contact_point_id] << "must be transmittable for that type of notification channel" if self.contact_point.nil? || !self.contact_point.transmittable?
end

#contact_point_is_websiteObject



118
119
120
# File 'app/models/notification_channel.rb', line 118

def contact_point_is_website
  errors[:contact_point_id] << "must be a website if #{PORTAL} is selected as transmission type" if self.contact_point.nil? or self.contact_point.category != ContactPoint::WEBSITE
end

#customerCustomer

Returns:

See Also:



76
# File 'app/models/notification_channel.rb', line 76

belongs_to :customer, optional: true

#is_email_or_faxObject



110
111
112
# File 'app/models/notification_channel.rb', line 110

def is_email_or_fax
  errors[:transmission_type] << "must be #{EMAIL_OR_FAX} for that type of notification channel" if self.transmission_type != EMAIL_OR_FAX
end