Class: VoidRmasWorker

Inherits:
Object
  • Object
show all
Includes:
Sidekiq::Job
Defined in:
app/workers/void_rmas_worker.rb

Overview

Sidekiq worker: void rmas.

Instance Method Summary collapse

Instance Method Details

#performObject



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

def perform
  three_months_old = Date.current.months_ago(3).to_time
  week_old = Date.current.weeks_ago(1).to_time
  # void rmas under awaiting return state and are more than 3 months old.
  old_rmas_on_awaiting_return = Rma.where(state: 'awaiting_return').where(company_id: [1, 2]).where(created_at: ...three_months_old)
  if old_rmas_on_awaiting_return.present?
    old_rmas_on_awaiting_return.each do |rma|
      rma.void_all_items_and_self
    rescue StandardError => e
      ErrorReporting.error e, rma_id: rma.id
    end
  end

  # void rmas under requested state and are more than 7 days old.
  old_rmas_on_requested = Rma.where(state: 'requested').where(created_at: ...week_old)
  return if old_rmas_on_requested.blank?

  old_rmas_on_requested.each do |rma|
    rma.void_all_items_and_self
  rescue StandardError => e
    ErrorReporting.error e, rma_id: rma.id
  end
end