Class: SpeedeeManifest
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- SpeedeeManifest
- 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
superseded_at :datetime
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)
Constant Summary
Constants included from Models::Schedulable
Models::Schedulable::SIMPLE_FORM_OPTIONS
Has many collapse
- #speedee_manifest_shipments ⇒ ActiveRecord::Relation<SpeedeeManifestShipment>
- #uploads ⇒ ActiveRecord::Relation<Upload>
Class Method Summary collapse
-
.drop_voided_shipments!(shipments) ⇒ void
Drops the given shipments off their manifests and flags those manifests for reprint.
-
.superseded ⇒ ActiveRecord::Relation<SpeedeeManifest>
A relation of SpeedeeManifests that are superseded.
Instance Method Summary collapse
-
#cancel_manifest ⇒ Object
Reverses a manifest run.
-
#emptied? ⇒ Boolean
True when every shipment has since been voided off the manifest — the printed sheet is now entirely wrong and there is nothing left to hand over.
-
#speedee_manifest_shipments_with_das ⇒ ActiveRecord::Relation<SpeedeeManifestShipment>
Manifest lines that carried a Delivery Area Surcharge, for the Additional Charges block on the driver summary.
-
#superseded? ⇒ Boolean
True once a shipment was voided off this manifest after it was printed, so the sheet the driver is holding overstates what's leaving the dock.
- #upload_summary_pdf(summary_pdf_path) ⇒ Boolean
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
Class Method Details
.drop_voided_shipments!(shipments) ⇒ void
This method returns an undefined value.
Drops the given shipments off their manifests and flags those manifests for
reprint.
Nothing is transmitted to Spee-Dee at close of day — the manifest exists so
the paper in the driver's hand matches Spee-Dee's dashboard and the parcels
actually on the truck. A void breaks all three at once: the Dispatch Science
order is cancelled, the parcel stays on the dock, but the manifest row (and
therefore the zone tables, charge rollups, totals and the scannable QR, all
of which Pdf::Document::SpeedeeSummary derives from these rows) still lists
it. Deleting the row is what makes a reprint truthful; superseded_at is only
the flag that tells the warehouse a reprint is owed.
Idempotent — a second void on the same manifest finds no rows to drop and
leaves the flag where it is.
44 45 46 47 48 49 50 51 |
# File 'app/models/speedee_manifest.rb', line 44 def self.drop_voided_shipments!(shipments) rows = SpeedeeManifestShipment.where(shipment_id: shipments.select(:id)) manifest_ids = rows.distinct.pluck(:speedee_manifest_id).compact return if manifest_ids.empty? rows.delete_all where(id: manifest_ids).update_all(superseded_at: Time.current, updated_at: Time.current) end |
.superseded ⇒ ActiveRecord::Relation<SpeedeeManifest>
A relation of SpeedeeManifests that are superseded. Active Record Scope
25 |
# File 'app/models/speedee_manifest.rb', line 25 scope :superseded, -> { where.not(superseded_at: nil) } |
Instance Method Details
#cancel_manifest ⇒ Object
Reverses a manifest run. Safe now that nothing is transmitted at close time
(the legacy CSV/FTP made this irreversible) — the manifest is a local record
plus a printed sheet, so it can be dropped and regenerated.
Only order-backed Deliveries carry the manifest_completed state to revert;
StandaloneDeliveries stay ship_labeled throughout and just lose their
manifest rows (compact avoids a nil crash on those).
94 95 96 97 |
# File 'app/models/speedee_manifest.rb', line 94 def cancel_manifest speedee_manifest_shipments.filter_map { |sms| sms.shipment&.delivery }.uniq.each(&:revert_to_pending_manifest_completion!) destroy! end |
#emptied? ⇒ Boolean
True when every shipment has since been voided off the manifest — the
printed sheet is now entirely wrong and there is nothing left to hand over.
63 |
# File 'app/models/speedee_manifest.rb', line 63 def emptied? = superseded? && speedee_manifest_shipments.empty? |
#speedee_manifest_shipments ⇒ ActiveRecord::Relation<SpeedeeManifestShipment>
21 |
# File 'app/models/speedee_manifest.rb', line 21 has_many :speedee_manifest_shipments, dependent: :destroy |
#speedee_manifest_shipments_with_das ⇒ ActiveRecord::Relation<SpeedeeManifestShipment>
Manifest lines that carried a Delivery Area Surcharge, for the Additional
Charges block on the driver summary. das is frozen into each row at
build time from the Dispatch Science quote's DAS charge line (the 2019
SpeedeeDasZip list is gone; historical rows were backfilled).
(An explicit method rather than delegate …, prefix: — YARD's DSL
handler crashes on that delegate form during the docs build.)
74 |
# File 'app/models/speedee_manifest.rb', line 74 def speedee_manifest_shipments_with_das = speedee_manifest_shipments.with_das # rubocop:disable Rails/Delegate -- YARD's DSL handler crashes on this delegate form |
#superseded? ⇒ Boolean
True once a shipment was voided off this manifest after it was printed, so
the sheet the driver is holding overstates what's leaving the dock.
57 |
# File 'app/models/speedee_manifest.rb', line 57 def superseded? = superseded_at.present? |
#upload_summary_pdf(summary_pdf_path) ⇒ Boolean
78 79 80 81 82 83 84 85 |
# File 'app/models/speedee_manifest.rb', line 78 def upload_summary_pdf(summary_pdf_path) upload = Upload.uploadify(summary_pdf_path, 'summary_pdf') if uploads << upload true else false end end |
#uploads ⇒ ActiveRecord::Relation<Upload>
23 |
# File 'app/models/speedee_manifest.rb', line 23 has_many :uploads, -> { order(position: :asc, created_at: :desc) }, as: :resource, dependent: :destroy |