Class: Mailing
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Mailing
- Includes:
- Models::Auditable
- Defined in:
- app/models/mailing.rb
Overview
== Schema Information
Table name: mailings
Database name: primary
id :integer not null, primary key
cover_file_size :integer
cover_letter_file_name :string(255)
cover_letter_type :string(255)
date_completed :datetime
description :text
label_content_type :string(255)
label_file_name :string(255)
label_file_size :integer
state :string(255)
created_at :datetime
updated_at :datetime
creator_id :integer
job_id :string(255)
store_id :integer
updater_id :integer
Indexes
index_mailings_on_store_id (store_id)
Foreign Keys
fk_rails_... (store_id => stores.id)
Constant Summary
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
- #activities ⇒ ActiveRecord::Relation<Activity>
- #mail_activities ⇒ ActiveRecord::Relation<MailActivity>
Instance Method Summary collapse
- #activity_ids ⇒ Object
- #activity_ids=(act_ids) ⇒ Object
- #addresses ⇒ Object
- #background_job ⇒ Object
- #generate_all_postage_labels_pdf ⇒ Object
- #has_active_background_job? ⇒ Boolean
- #ok_to_delete? ⇒ Boolean
- #ready_to_complete? ⇒ Boolean
- #to_s ⇒ 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 Method Details
#activities ⇒ ActiveRecord::Relation<Activity>
37 |
# File 'app/models/mailing.rb', line 37 has_many :activities, through: :mail_activities |
#activity_ids ⇒ Object
68 69 70 |
# File 'app/models/mailing.rb', line 68 def activity_ids mail_activities.pluck(:activity_id) end |
#activity_ids=(act_ids) ⇒ Object
62 63 64 65 66 |
# File 'app/models/mailing.rb', line 62 def activity_ids=(act_ids) act_ids.each do |act_id| mail_activities << MailActivity.create(mailing_id: id, activity_id: act_id) end end |
#addresses ⇒ Object
82 83 84 |
# File 'app/models/mailing.rb', line 82 def addresses mail_activities.map(&:mailing_address) end |
#background_job ⇒ Object
72 73 74 75 76 |
# File 'app/models/mailing.rb', line 72 def background_job return unless job_id BackgroundJobStatus.find(job_id) end |
#generate_all_postage_labels_pdf ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/models/mailing.rb', line 94 def generate_all_postage_labels_pdf upload = nil files_to_combine = [] nil msg_arr = [] mail_activities_to_print = mail_activities.complete.select(&:ready_to_print_labels?) t = mail_activities_to_print.length p = 0 mail_activities_to_print.each do |ma| pdf = ma.all_labels_pdf&.&.path if pdf files_to_combine << pdf p += 1 else msg_arr << ma.name.to_s end rescue Dragonfly::Job::Fetch::NotFound msg_arr << ma.name.to_s end unless files_to_combine.empty? file_name = "all_postage_labels_mailing_#{id}_#{Time.current.strftime('%m_%d_%Y_%I_%M%p')}.pdf".downcase output_file_path = Upload.temp_location(file_name) all_postage_labels_path = PdfTools.combine(files_to_combine, output_file_path: output_file_path) upload = Upload.uploadify(all_postage_labels_path, "all_postage_labels_path_pdf") end msg = "Processed #{p} of #{t} mail activities. " msg += "Postage Labels could not generate for #{msg_arr.join(', ')}." unless msg_arr.empty? [upload, msg] end |
#has_active_background_job? ⇒ Boolean
78 79 80 |
# File 'app/models/mailing.rb', line 78 def has_active_background_job? background_job&.active? end |
#mail_activities ⇒ ActiveRecord::Relation<MailActivity>
36 |
# File 'app/models/mailing.rb', line 36 has_many :mail_activities, dependent: :destroy |
#ok_to_delete? ⇒ Boolean
90 91 92 |
# File 'app/models/mailing.rb', line 90 def ok_to_delete? !complete? && mail_activities.all?(&:ok_to_delete?) end |
#ready_to_complete? ⇒ Boolean
86 87 88 |
# File 'app/models/mailing.rb', line 86 def ready_to_complete? mail_activities.all?(&:complete?) end |
#store ⇒ Store
Validations:
35 |
# File 'app/models/mailing.rb', line 35 belongs_to :store, optional: true |
#to_s ⇒ Object
58 59 60 |
# File 'app/models/mailing.rb', line 58 def to_s "Mailing #{id}" end |