Class: Shipping::SpeedeeManifestGenerator

Inherits:
BaseService
  • Object
show all
Defined in:
app/services/shipping/speedee_manifest_generator.rb

Overview

Service object: speedee manifest generator.

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Attributes inherited from BaseService

#options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

#log_debug, #log_error, #log_info, #log_warning, #logger, #tagged_logger

Constructor Details

#initialize(_options = {}) ⇒ SpeedeeManifestGenerator

Returns a new instance of SpeedeeManifestGenerator.



13
14
15
# File 'app/services/shipping/speedee_manifest_generator.rb', line 13

def initialize(_options = {})
  @renderer = PdfRenderer.new
end

Instance Attribute Details

#rendererObject (readonly)

Returns the value of attribute renderer.



11
12
13
# File 'app/services/shipping/speedee_manifest_generator.rb', line 11

def renderer
  @renderer
end

Class Method Details

.manifestable_shipments(store) ⇒ ActiveRecord::Relation<Shipment>

Shipments that belong on tonight's driver summary.

ORDER DELIVERIES ONLY. Standalone parcels are deliberately excluded: they
never get a Dispatch Science order (they carry our legacy PD-prefixed
synthesized barcode), so a standalone line on the driver summary is a line
Spee-Dee's system has no record of — and Spee-Dee reprocesses this sheet
for billing. Standalone delivery 103 proved it on the 2026-07-31 manifest:
a parcel labeled 2026-04-08 sat in ship_labeled for 16 weeks until the old
unbounded where.missing(:speedee_manifest_shipment) term swept it onto
the sheet as SP02969203PD1410205, four months after it was packed.

pending_manifest_completion is transient, so this needs no date bound — a
delivery leaves that state the moment the manifest closes.

Parameters:

Returns:



33
34
35
36
37
38
39
40
# File 'app/services/shipping/speedee_manifest_generator.rb', line 33

def self.manifestable_shipments(store)
  Shipment.where(
    delivery_id: Delivery.with_shipment_carrier('SpeedeeDelivery')
                         .pending_manifest_completion
                         .by_store_id(store.id)
                         .select(:id)
  ).label_complete.order(:id)
end

Instance Method Details

#process(store, _options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/services/shipping/speedee_manifest_generator.rb', line 42

def process(store, _options = {})
  success = false
  shipments = self.class.manifestable_shipments(store)
  # No CSV/FTP: API-booked shipments are already registered with Spee-Dee;
  # only the driver summary PDF is produced (Hunter Boelz, 2026-07-17).
  res = SpeedeeManifestShipment.create_entries_and_manifest(shipments)
  message = res[:message]
  if res[:success]
    success = true
    speedee_manifest = res[:speedee_manifest]
    summary_result = Pdf::Document::SpeedeeSummary.call(store, speedee_manifest)
    summary_pdf_upload = Upload.uploadify_from_data(file_name: summary_result.pdf_file_name, data: summary_result.pdf, category: 'summary_pdf', resource: speedee_manifest)
    Result.new(success: success, message: message, pdf: summary_result.pdf, pdf_file_name: summary_result.pdf_file_name, summary_pdf_upload: summary_pdf_upload)
  else
    Result.new(success: success, message: message, pdf: nil, pdf_file_name: nil, summary_pdf_upload: nil)
  end
end