Class: GeneratePickSlipWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job, Workers::StatusBroadcastable
Defined in:
app/workers/generate_pick_slip_worker.rb

Overview

Sidekiq worker: generate pick slip.

Instance Attribute Summary

Attributes included from Workers::StatusBroadcastable

#broadcast_status_updates

Instance Method Summary collapse

Methods included from Workers::StatusBroadcastable::Overrides

#at, #store, #total

Instance Method Details

#perform(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})

    job options

Options Hash (options):

  • delivery_ids (Array<Integer>)

    deliveries to generate pick slips for (multiple: super pick slip)

  • store_id (Integer)

    warehouse store to redirect to when the job completes

  • split_kits (Boolean)

    split kit items into components on the pick slip

  • print_profile_id (Integer)

    PrintProfile to send the PDF directly to



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/workers/generate_pick_slip_worker.rb', line 15

def perform(options = {})
  deliveries = Delivery.where(id: options[:delivery_ids])
  store = begin
    Store.find(options[:store_id])
  rescue StandardError
    nil
  end
  store ||= deliveries.first&.store&.id
  pdf_upload_id = nil
  pdf = nil
  msg = []
  if deliveries.present?
    if deliveries.size > 1 # Super pick slip
      pdf, sub_msg = Delivery.generate_super_pick_slip_pdf(deliveries, options[:split_kits])
      msg << sub_msg
    elsif (d = deliveries.first) # Just get it directly for a single one
      msg << d.name
      pdf = d.get_or_generate_pick_slip_pdf(options[:split_kits])
    end
    pdf_upload_id = pdf.id
    if (ppid = options[:print_profile_id].presence) # Directly send to printer!
      pp = PrintProfile.find(ppid)
      jid = pp.print_upload(pdf)
      msg << "- Submitted pdf upload #{pdf.id} to print profile #{pp.name} [#{ppid}], job #{jid}"
    end
  end
  store upload_id: pdf_upload_id
  store redirect_to: "/warehouses/#{store.id}"
  store complete_message: msg.join('. ')
end