Class: LiabilityInsurance
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LiabilityInsurance
- Includes:
- Models::Auditable, Models::LiquidMethods
- Defined in:
- app/models/liability_insurance.rb
Overview
== Schema Information
Table name: liability_insurances
Database name: primary
id :bigint not null, primary key
attachment_name :string
attachment_uid :string
expiration_date :datetime
expiration_reminder_sent :boolean default(FALSE)
expiration_reminder_sent_on :datetime
expired_alert_sent :boolean default(FALSE)
expired_alert_sent_on :datetime
state :string
valid_from_date :datetime
created_at :datetime not null
updated_at :datetime not null
customer_id :integer
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #attachment ⇒ Object readonly
- #expiration_date ⇒ ActiveSupport::TimeWithZone readonly
- #valid_from_date ⇒ ActiveSupport::TimeWithZone readonly
Belongs to collapse
Methods included from Models::Auditable
Class Method Summary collapse
-
.active ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are active.
-
.effective_now ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective now.
-
.effective_on ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective on.
-
.requested ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are requested.
Instance Method Summary collapse
- #has_valid_date_range ⇒ void
- #is_valid? ⇒ Boolean
- #liability_insurance_link ⇒ void
- #notify_new_upload ⇒ void
- #only_one_active ⇒ void
- #period ⇒ void
- #possible_events ⇒ void
- #possible_events_for_select ⇒ void
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::Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#attachment ⇒ Object (readonly)
41 |
# File 'app/models/liability_insurance.rb', line 41 validates :attachment, presence: true |
#expiration_date ⇒ ActiveSupport::TimeWithZone (readonly)
37 |
# File 'app/models/liability_insurance.rb', line 37 validates :expiration_date, presence: true |
#valid_from_date ⇒ ActiveSupport::TimeWithZone (readonly)
39 |
# File 'app/models/liability_insurance.rb', line 39 validates :valid_from_date, presence: true |
Class Method Details
.active ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are active. Active Record Scope
50 |
# File 'app/models/liability_insurance.rb', line 50 scope :active, -> { where(state: 'active') } |
.effective_now ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective now. Active Record Scope
48 |
# File 'app/models/liability_insurance.rb', line 48 scope :effective_now, -> { active.effective_on(Time.current) } |
.effective_on ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are effective on. Active Record Scope
47 |
# File 'app/models/liability_insurance.rb', line 47 scope :effective_on, ->(date) { where("valid_from_date <= ? and expiration_date >= ?", date || Time.current, date || Time.current) } |
.requested ⇒ ActiveRecord::Relation<LiabilityInsurance>
A relation of LiabilityInsurances that are requested. Active Record Scope
49 |
# File 'app/models/liability_insurance.rb', line 49 scope :requested, -> { where(state: 'processing') } |
Instance Method Details
#customer ⇒ Customer?
30 |
# File 'app/models/liability_insurance.rb', line 30 belongs_to :customer, optional: true |
#has_valid_date_range ⇒ void
This method returns an undefined value.
92 93 94 95 96 97 |
# File 'app/models/liability_insurance.rb', line 92 def has_valid_date_range # Check dates are in order return unless valid_from_date && expiration_date errors.add(:base, "date range is invalid") if valid_from_date > expiration_date end |
#is_valid? ⇒ Boolean
82 83 84 |
# File 'app/models/liability_insurance.rb', line 82 def is_valid? Date.current.between?(valid_from_date, expiration_date) end |
#liability_insurance_link ⇒ void
This method returns an undefined value.
120 121 122 |
# File 'app/models/liability_insurance.rb', line 120 def liability_insurance_link "#{WEB_URL}/my_account/liability_insurances" end |
#notify_new_upload ⇒ void
This method returns an undefined value.
115 116 117 |
# File 'app/models/liability_insurance.rb', line 115 def notify_new_upload TrainingMailer.new_liability_insurance_card(self).deliver_later end |
#only_one_active ⇒ void
This method returns an undefined value.
100 101 102 |
# File 'app/models/liability_insurance.rb', line 100 def only_one_active errors.add(:base, "there is currently another insurance card active and valid") if state == 'active' && is_valid? end |
#party ⇒ Party?
28 |
# File 'app/models/liability_insurance.rb', line 28 belongs_to :party, foreign_key: 'customer_id', optional: true |
#period ⇒ void
This method returns an undefined value.
87 88 89 |
# File 'app/models/liability_insurance.rb', line 87 def period valid_from_date..expiration_date end |
#possible_events ⇒ void
This method returns an undefined value.
105 106 107 |
# File 'app/models/liability_insurance.rb', line 105 def possible_events state_transitions.map(&:event).sort end |
#possible_events_for_select ⇒ void
This method returns an undefined value.
110 111 112 |
# File 'app/models/liability_insurance.rb', line 110 def possible_events_for_select possible_events.map { |evt| [evt.to_s.titleize, evt] } end |