Class: QuoteCopyWorker

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

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



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/workers/quote_copy_worker.rb', line 7

def perform(options = {})
  options = options.symbolize_keys
  opportunity_copying_to = Opportunity.find(options[:opportunity_id])
  current_quote = Quote.find(options[:quote_id])
  notify_email = options[:notify_email]

  report = Quote::Copier.new(current_quote).copy_to(opportunity_copying_to) do |current_step, total_steps, message|
    total total_steps
    at(current_step, message)
  end

  new_quote = report[:new_quote].present? ? Quote.find(report[:new_quote].first.to_i) : nil
  if report[:errors].any?
    store redirect_to: "/quotes/#{current_quote.id}"
    InternalMailer.quote_copy_complete(opportunity_copying_to, new_quote, user_email: notify_email, report: report).deliver_now
    message = report[:errors].first
    store message: message
  else
    message = report[:successes].first
    store redirect_to: "/quotes/#{new_quote.id}"
    store message: message
  end
end