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 =
Orders shipment.
'ORS'.freeze
- INVOICES =
Invoices.
'invoices'.freeze
- RMA =
Rma.
'RMA'.freeze
- CREDIT_MEMOS =
Credit memos.
'credit_memos'.freeze
- STATEMENT_OF_ACCOUNTS =
Statement of accounts.
'statement_of_accounts'.freeze
- EMAIL_OR_FAX =
Email or fax.
'Email/Fax'.freeze
- MAIL =
Mail.
'Mail'.freeze
- PORTAL =
Portal.
'Portal'.freeze
- EDI =
Edi.
'EDI'.freeze
- NOTIFICATION_TYPES =
Recognised notification types.
{ 'Order Shipment Notifications': ORDERS_SHIPMENT, Invoices: INVOICES, RMA: RMA, 'Credit Memos': CREDIT_MEMOS, 'Statement of Accounts': STATEMENT_OF_ACCOUNTS }.freeze
- TRANSMISSION_TYPES =
Recognised transmission types.
[EMAIL_OR_FAX, MAIL, PORTAL, EDI].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #contact_point_id ⇒ Object readonly
- #customer_id ⇒ Object readonly
- #notification_type ⇒ Object readonly
- #transmission_type ⇒ Object readonly
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 Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#contact_point_id ⇒ Object (readonly)
91 |
# File 'app/models/notification_channel.rb', line 91 validates :contact_point_id, presence: { unless: proc { |nc| [MAIL, EDI].include?(nc.transmission_type) }, message: "is required for that type of notification channel" } |
#customer_id ⇒ Object (readonly)
92 |
# File 'app/models/notification_channel.rb', line 92 validates :notification_type, :transmission_type, :customer_id, presence: true |
#notification_type ⇒ Object (readonly)
92 |
# File 'app/models/notification_channel.rb', line 92 validates :notification_type, :transmission_type, :customer_id, presence: true |
#transmission_type ⇒ Object (readonly)
92 |
# File 'app/models/notification_channel.rb', line 92 validates :notification_type, :transmission_type, :customer_id, presence: true |
Class Method Details
.contact_points_for_select(customer) ⇒ Object
115 116 117 118 |
# File 'app/models/notification_channel.rb', line 115 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
103 |
# File 'app/models/notification_channel.rb', line 103 scope :credit_memos, -> { where(notification_type: CREDIT_MEMOS) } |
.email ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are email. Active Record Scope
101 |
# File 'app/models/notification_channel.rb', line 101 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
104 |
# File 'app/models/notification_channel.rb', line 104 scope :fallback_enabled, -> { where(fallback_for_subsidiaries: true) } |
.fax ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are fax. Active Record Scope
102 |
# File 'app/models/notification_channel.rb', line 102 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
105 |
# File 'app/models/notification_channel.rb', line 105 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
99 |
# File 'app/models/notification_channel.rb', line 99 scope :invoices, -> { where(notification_type: INVOICES) } |
.notification_types_for_select ⇒ Object
107 108 109 |
# File 'app/models/notification_channel.rb', line 107 def self.notification_types_for_select NotificationChannel::NOTIFICATION_TYPES.map { |k, v| [k, v] } end |
.orders_shipment ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are orders shipment. Active Record Scope
98 |
# File 'app/models/notification_channel.rb', line 98 scope :orders_shipment, -> { where(notification_type: ORDERS_SHIPMENT) } |
.rmas ⇒ ActiveRecord::Relation<NotificationChannel>
A relation of NotificationChannels that are rmas. Active Record Scope
100 |
# File 'app/models/notification_channel.rb', line 100 scope :rmas, -> { where(notification_type: NotificationChannel::RMA) } |
.transmission_types_for_select ⇒ Object
111 112 113 |
# File 'app/models/notification_channel.rb', line 111 def self.transmission_types_for_select NotificationChannel::TRANSMISSION_TYPES.map { |tt| [tt, tt] } end |
Instance Method Details
#clear_contact_point_id ⇒ Object
132 133 134 |
# File 'app/models/notification_channel.rb', line 132 def clear_contact_point_id self.contact_point_id = nil end |
#contact_point ⇒ ContactPoint
87 |
# File 'app/models/notification_channel.rb', line 87 belongs_to :contact_point, optional: true |
#contact_point_is_transmittable ⇒ Object
124 125 126 |
# File 'app/models/notification_channel.rb', line 124 def contact_point_is_transmittable errors.add(:contact_point_id, "must be transmittable for that type of notification channel") if contact_point.nil? || !contact_point.transmittable? end |
#contact_point_is_website ⇒ Object
128 129 130 |
# File 'app/models/notification_channel.rb', line 128 def contact_point_is_website errors.add(:contact_point_id, "must be a website if #{PORTAL} is selected as transmission type") if contact_point.nil? || (contact_point.category != ContactPoint::WEBSITE) end |
#customer ⇒ Customer
86 |
# File 'app/models/notification_channel.rb', line 86 belongs_to :customer, optional: true |
#is_email_or_fax ⇒ Object
120 121 122 |
# File 'app/models/notification_channel.rb', line 120 def is_email_or_fax errors.add(:transmission_type, "must be #{EMAIL_OR_FAX} for that type of notification channel") if transmission_type != EMAIL_OR_FAX end |