Class: Manifest

Inherits:
ApplicationRecord show all
Includes:
Models::Auditable
Defined in:
app/models/manifest.rb

Overview

== Schema Information

Table name: manifests
Database name: primary

id :integer not null, primary key
carrier :string not null
state :string
created_at :datetime
updated_at :datetime
carrier_account_id :string not null
creator_id :integer
legacy_ep_manifest_id :string not null
store_id :integer not null
updater_id :integer

Indexes

index_manifests_on_carrier (carrier)
index_manifests_on_carrier_account_id (carrier_account_id)
index_manifests_on_legacy_ep_manifest_id (legacy_ep_manifest_id)
index_manifests_on_store_id (store_id)

Constant Summary

Constants included from Models::Auditable

Models::Auditable::ALWAYS_IGNORED

Instance Attribute Summary collapse

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Has many collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#publish_event

Instance Attribute Details

#carrierObject (readonly)



32
# File 'app/models/manifest.rb', line 32

validates :carrier, presence: true

#carrier_account_idObject (readonly)



33
# File 'app/models/manifest.rb', line 33

validates :carrier_account_id, presence: true

#legacy_ep_manifest_idObject (readonly)



34
# File 'app/models/manifest.rb', line 34

validates :legacy_ep_manifest_id, presence: true

Class Method Details

.all_generated_todayActiveRecord::Relation<Manifest>

A relation of Manifests that are all generated today. Active Record Scope

Returns:

See Also:



45
# File 'app/models/manifest.rb', line 45

scope :all_generated_today, -> { for_today.complete }

.all_generatingActiveRecord::Relation<Manifest>

A relation of Manifests that are all generating. Active Record Scope

Returns:

See Also:



43
# File 'app/models/manifest.rb', line 43

scope :all_generating, -> { where(state: 'created') }

.completeActiveRecord::Relation<Manifest>

A relation of Manifests that are complete. Active Record Scope

Returns:

See Also:



42
# File 'app/models/manifest.rb', line 42

scope :complete, -> { where(state: 'complete') }

.for_carrierActiveRecord::Relation<Manifest>

A relation of Manifests that are for carrier. Active Record Scope

Returns:

See Also:



39
# File 'app/models/manifest.rb', line 39

scope :for_carrier, ->(carrier) { where(carrier:) }

.for_carrier_account_idActiveRecord::Relation<Manifest>

A relation of Manifests that are for carrier account id. Active Record Scope

Returns:

See Also:



40
# File 'app/models/manifest.rb', line 40

scope :for_carrier_account_id, ->() { where(carrier_account_id:) }

.for_todayActiveRecord::Relation<Manifest>

A relation of Manifests that are for today. Active Record Scope

Returns:

See Also:



41
# File 'app/models/manifest.rb', line 41

scope :for_today, -> { where(['(created_at >= ?) and (created_at <= ?)', Time.current.beginning_of_day, Time.current.end_of_day]) }

.generated_todayActiveRecord::Relation<Manifest>

A relation of Manifests that are generated today. Active Record Scope

Returns:

See Also:



46
# File 'app/models/manifest.rb', line 46

scope :generated_today, ->() { ().for_today.complete }

.generatingActiveRecord::Relation<Manifest>

A relation of Manifests that are generating. Active Record Scope

Returns:

See Also:



44
# File 'app/models/manifest.rb', line 44

scope :generating, ->() { where(state: 'created').() }

Instance Method Details

#generate_manifest_pdf(manifest_pdf_url) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'app/models/manifest.rb', line 75

def generate_manifest_pdf(manifest_pdf_url)
  manifest_pdf_file = Tempfile.new("manifest_#{id}_pdf.pdf")
  manifest_pdf_file.binmode
  manifest_pdf_file << URI.open(manifest_pdf_url).read
  manifest_pdf_file.flush
  manifest_pdf_file.fsync
  manifest_pdf_file.rewind
  file_name = "manifest_#{id}_pdf.pdf"
  manifest_pdf_path = Upload.temp_location(file_name)
  FileUtils.cp(manifest_pdf_file.path, manifest_pdf_path)
  upload = Upload.uploadify(manifest_pdf_path, 'manifest_pdf')
  logger.debug "shipment: #{id}, generate_manifest_pdf: upload: #{upload.inspect}"
  return true if uploads << upload

  false
end

#manifest_pdfObject



71
72
73
# File 'app/models/manifest.rb', line 71

def manifest_pdf
  uploads.manifest_pdfs.order(:created_at).reverse_order.first
end

#set_multi_shipment_delivery_manifestObject



92
93
94
95
96
# File 'app/models/manifest.rb', line 92

def set_multi_shipment_delivery_manifest
  shipments.each do |shipment|
    shipment.delivery.mark_multi_shipments_manifested(self, shipment)
  end
end

#shipmentsActiveRecord::Relation<Shipment>

Returns:

See Also:



28
# File 'app/models/manifest.rb', line 28

has_many :shipments, inverse_of: :manifest, dependent: :nullify

#storeStore

Returns:

See Also:

Validations:



27
# File 'app/models/manifest.rb', line 27

belongs_to :store, inverse_of: :manifests, optional: true

#uploadsActiveRecord::Relation<Upload>

Returns:

  • (ActiveRecord::Relation<Upload>)

See Also:



29
# File 'app/models/manifest.rb', line 29

has_many :uploads, as: :resource, dependent: :destroy