Class: DeliveryLabelTrackingPrefillWorker
- Inherits:
-
Object
- Object
- DeliveryLabelTrackingPrefillWorker
- Includes:
- Sidekiq::Job
- Defined in:
- app/workers/delivery_label_tracking_prefill_worker.rb
Overview
Pre-fills a manual delivery's tracking number from the shipping label
somebody already uploaded, so warehouse staff confirm a number instead of
reading it off a label and typing it.
Why this exists: labels bought outside Heatwave (ShipStation for the
Canada warehouse, Seller Central for Amazon FBA transfers) carry more
than one barcode, and the wrong one gets keyed. 33 Canpar deliveries in
90 days went out with the label's 16-digit barcode instead of the D
number Canpar actually tracks, which leaves the CRM tracking link dead
and the shipment reporting no delivery events, ever.
Runs on the transition into pending_ship_labels, which is the last
moment before the ship-label screen is opened. Every one of the 41
affected orders had its label uploaded before that point, so by the time
this fires the file is there.
Deliberately does not overwrite: a number already on the shipment or the
delivery wins, because a human put it there.
Constant Summary collapse
- PLACEHOLDER_CARRIERS =
Carrier strings that mean "nobody has chosen yet", so the carrier read
off the label is an improvement rather than an override of a decision. /\Aoverride|\Astandard\z|please confirm/i
Instance Method Summary collapse
Instance Method Details
#perform(delivery_id) ⇒ void
This method returns an undefined value.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/workers/delivery_label_tracking_prefill_worker.rb', line 38 def perform(delivery_id) delivery = Delivery.find_by(id: delivery_id) return unless delivery&.pending_ship_labels? return if delivery.shipments.completed.any? shipments = delivery.shipments.packed_or_awaiting_labels.to_a return if shipments.empty? return if delivery.master_tracking_number.present? && shipments.all? { |s| s.tracking_number.present? } hit = read_label(delivery) return if hit.nil? if shipments.one? fill_shipment(shipments.first, hit) else # More than one carton: the label sheet holds a number per box, but # nothing ties label page order to shipment order, and guessing wrong # points a customer at somebody else's parcel. Set the master and let # the existing manual-label path fan it out. fill_master(delivery, hit) end end |