Class: EditReceiptsWorker

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

Overview

Sidekiq worker: edit receipts.

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):

  • upload_id (Integer)

    ID of the uploaded XLSX file of receipt edits



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/workers/edit_receipts_worker.rb', line 12

def perform(options = {})
  excel_file = Upload.find_by(id: options[:upload_id])

  report = Receipt.edit_receipts_from_xlsx(excel_file) do |current_step, total_steps, message|
    total total_steps
    at(current_step, message)
  end

  excel_file.destroy

  if report[:errors].any?
    message = report[:errors].join('. ')
    store redirect_to: '/receipts/edit_from_excel'
    store error_message: message
  else
    message = report[:successes].join('. ')
    store redirect_to: "/receipts/edited?edited_receipt_ids%5B%5D=#{report[:edited_receipt_ids].join('&edited_receipt_ids%5B%5D=')}"
    store message: message
  end
end