Class: SpeedeeManifest

Inherits:
ApplicationRecord show all
Defined in:
app/models/speedee_manifest.rb

Overview

== Schema Information

Table name: speedee_manifests
Database name: primary

id :integer not null, primary key
filename :string not null
transmitted_at :datetime not null
created_at :datetime not null
updated_at :datetime not null

Indexes

index_speedee_manifests_on_filename (filename)
index_speedee_manifests_on_transmitted_at (transmitted_at)

Has many collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Method Details

#cancel_manifestObject



46
47
48
49
50
51
52
# File 'app/models/speedee_manifest.rb', line 46

def cancel_manifest
  dels = self.speedee_manifest_shipments.map{|sms| sms.delivery}.uniq
  dels.each do |d|
    d.revert_to_pending_manifest_completion!
  end
  self.destroy!
end

#speedee_manifest_shipmentsActiveRecord::Relation<SpeedeeManifestShipment>

Returns:

See Also:



19
# File 'app/models/speedee_manifest.rb', line 19

has_many :speedee_manifest_shipments, dependent: :destroy

#speedee_manifest_shipments_with_dasObject



22
23
24
25
26
# File 'app/models/speedee_manifest.rb', line 22

def speedee_manifest_shipments_with_das
  # doing it this way so I can fake it as a scope ie ActiveRecord CollectionProxy
  with_das_ids = speedee_manifest_shipments.select{|sms| SpeedeeDasZip.where(zip: sms.ship_to_zip).first.present?}.map{|sms| sms.id}.uniq
  SpeedeeManifestShipment.where(id: with_das_ids)
end

#upload_manifest_csv(manifest_csv_path) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/models/speedee_manifest.rb', line 37

def upload_manifest_csv(manifest_csv_path)
  upload = Upload.uploadify(manifest_csv_path, 'manifest_csv')
  if self.uploads << upload
    return true
  else
    return false
  end
end

#upload_summary_pdf(summary_pdf_path) ⇒ Object



28
29
30
31
32
33
34
35
# File 'app/models/speedee_manifest.rb', line 28

def upload_summary_pdf(summary_pdf_path)
  upload = Upload.uploadify(summary_pdf_path, 'summary_pdf')
  if self.uploads << upload
    return true
  else
    return false
  end
end

#uploadsActiveRecord::Relation<Upload>

Returns:

  • (ActiveRecord::Relation<Upload>)

See Also:



20
# File 'app/models/speedee_manifest.rb', line 20

has_many :uploads, -> { order(position: :asc, created_at: :desc) }, as: :resource, dependent: :destroy