Class: NotificationChannel
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- NotificationChannel
- 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
Class Method Summary collapse
- .contact_points_for_select(customer) ⇒ Object
-
.credit_memos ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are credit memos.
-
.email ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are email.
-
.fallback_enabled ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are fallback enabled.
-
.fax ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are fax.
-
.for_customer ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are for customer.
-
.invoices ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are invoices.
- .notification_types_for_select ⇒ Object
-
.orders_shipment ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are orders shipment.
-
.rmas ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are rmas.
- .transmission_types_for_select ⇒ Object
Instance Method Summary collapse
- #clear_contact_point_id ⇒ Object
- #contact_point_is_transmittable ⇒ Object
- #contact_point_is_website ⇒ Object
- #is_email_or_fax ⇒ 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
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_memos ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are credit memos. Active Record Scope
93 |
# File 'app/models/notification_channel.rb', line 93 scope :credit_memos, -> { where(notification_type: CREDIT_MEMOS) } |
.email ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are email. Active Record Scope
91 |
# File 'app/models/notification_channel.rb', line 91 scope :email, -> { eager_load(:contact_point).merge(ContactPoint.emails) } |
.fallback_enabled ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are fallback enabled. Active Record Scope
94 |
# File 'app/models/notification_channel.rb', line 94 scope :fallback_enabled, -> { where(fallback_for_subsidiaries: true) } |
.fax ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are fax. Active Record Scope
92 |
# File 'app/models/notification_channel.rb', line 92 scope :fax, -> { eager_load(:contact_point).merge(ContactPoint.faxes) } |
.for_customer ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are for customer. Active Record Scope
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)) } |
.invoices ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are invoices. Active Record Scope
89 |
# File 'app/models/notification_channel.rb', line 89 scope :invoices, -> { where(notification_type: INVOICES) } |
.notification_types_for_select ⇒ Object
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_shipment ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are orders shipment. Active Record Scope
88 |
# File 'app/models/notification_channel.rb', line 88 scope :orders_shipment, -> { where(notification_type: ORDERS_SHIPMENT) } |
.rmas ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are rmas. Active Record Scope
90 |
# File 'app/models/notification_channel.rb', line 90 scope :rmas, -> { where(notification_type: NotificationChannel::RMA) } |
.transmission_types_for_select ⇒ Object
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_id ⇒ Object
122 123 124 |
# File 'app/models/notification_channel.rb', line 122 def clear_contact_point_id self.contact_point_id = nil end |
#contact_point ⇒ ContactPoint
77 |
# File 'app/models/notification_channel.rb', line 77 belongs_to :contact_point, optional: true |
#contact_point_is_transmittable ⇒ Object
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_website ⇒ Object
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 |
#customer ⇒ Customer
76 |
# File 'app/models/notification_channel.rb', line 76 belongs_to :customer, optional: true |
#is_email_or_fax ⇒ Object
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 |