Class: OpportunityCopyWorker
- Inherits:
-
Object
- Object
- OpportunityCopyWorker
- Includes:
- Sidekiq::Job, Workers::StatusBroadcastable
- Defined in:
- app/workers/opportunity_copy_worker.rb
Overview
Sidekiq worker: opportunity copy.
Instance Attribute Summary
Attributes included from Workers::StatusBroadcastable
Instance Method Summary collapse
Methods included from Workers::StatusBroadcastable::Overrides
Instance Method Details
#perform(options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/workers/opportunity_copy_worker.rb', line 8 def perform( = {}) = .symbolize_keys = Customer.find([:customer_id]) current_opportunity = Opportunity.find([:opportunity_id]) quotes_ids_to_copy = [:quote_ids] notify_email = [:notify_email] report = Opportunity::Copier.new(current_opportunity, quotes_ids_to_copy).copy_to() do |current_step, total_steps, | total total_steps at(current_step, ) end new_opp_id = report[:new_opportunity].present? ? Opportunity.find(report[:new_opportunity].first.to_i) : nil if report[:errors].any? store redirect_to: "/opportunities/#{current_opportunity.id}" SalesMailer.opportunity_copy_complete(, new_opp_id, user_email: notify_email, report: report).deliver_now = report[:errors].first store message: else = report[:successes].first store redirect_to: "/opportunities/#{new_opp_id.id}" store message: end end |