Class: Manifest
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Manifest
- 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
- #carrier ⇒ Object readonly
- #carrier_account_id ⇒ Object readonly
- #legacy_ep_manifest_id ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Has many collapse
Class Method Summary collapse
-
.all_generated_today ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are all generated today.
-
.all_generating ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are all generating.
-
.complete ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are complete.
-
.for_carrier ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are for carrier.
-
.for_carrier_account_id ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are for carrier account id.
-
.for_today ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are for today.
-
.generated_today ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are generated today.
-
.generating ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are generating.
Instance Method Summary collapse
- #generate_manifest_pdf(manifest_pdf_url) ⇒ Object
- #manifest_pdf ⇒ Object
- #set_multi_shipment_delivery_manifest ⇒ 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 Models::EventPublishable
Instance Attribute Details
#carrier ⇒ Object (readonly)
32 |
# File 'app/models/manifest.rb', line 32 validates :carrier, presence: true |
#carrier_account_id ⇒ Object (readonly)
33 |
# File 'app/models/manifest.rb', line 33 validates :carrier_account_id, presence: true |
#legacy_ep_manifest_id ⇒ Object (readonly)
34 |
# File 'app/models/manifest.rb', line 34 validates :legacy_ep_manifest_id, presence: true |
Class Method Details
.all_generated_today ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are all generated today. Active Record Scope
45 |
# File 'app/models/manifest.rb', line 45 scope :all_generated_today, -> { for_today.complete } |
.all_generating ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are all generating. Active Record Scope
43 |
# File 'app/models/manifest.rb', line 43 scope :all_generating, -> { where(state: 'created') } |
.complete ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are complete. Active Record Scope
42 |
# File 'app/models/manifest.rb', line 42 scope :complete, -> { where(state: 'complete') } |
.for_carrier ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are for carrier. Active Record Scope
39 |
# File 'app/models/manifest.rb', line 39 scope :for_carrier, ->(carrier) { where(carrier:) } |
.for_carrier_account_id ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are for carrier account id. Active Record Scope
40 |
# File 'app/models/manifest.rb', line 40 scope :for_carrier_account_id, ->(carrier_account_id) { where(carrier_account_id:) } |
.for_today ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are for today. Active Record Scope
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_today ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are generated today. Active Record Scope
46 |
# File 'app/models/manifest.rb', line 46 scope :generated_today, ->(carrier_account_id) { for_carrier_account_id(carrier_account_id).for_today.complete } |
.generating ⇒ ActiveRecord::Relation<Manifest>
A relation of Manifests that are generating. Active Record Scope
44 |
# File 'app/models/manifest.rb', line 44 scope :generating, ->(carrier_account_id) { where(state: 'created').for_carrier_account_id(carrier_account_id) } |
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_pdf ⇒ Object
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_manifest ⇒ Object
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 |
#shipments ⇒ ActiveRecord::Relation<Shipment>
28 |
# File 'app/models/manifest.rb', line 28 has_many :shipments, inverse_of: :manifest, dependent: :nullify |
#store ⇒ Store
Validations:
27 |
# File 'app/models/manifest.rb', line 27 belongs_to :store, inverse_of: :manifests, optional: true |
#uploads ⇒ ActiveRecord::Relation<Upload>
29 |
# File 'app/models/manifest.rb', line 29 has_many :uploads, as: :resource, dependent: :destroy |