Class: VoidRmasWorker

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

Instance Method Summary collapse

Instance Method Details

#performObject



5
6
7
8
9
10
11
12
13
14
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
# File 'app/workers/void_rmas_worker.rb', line 5

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|
      begin
        rma.void_all_items_and_self
      rescue StandardError => exc
        ErrorReporting.error exc, rma_id: rma.id
      end
    end
  end

  #void rmas under awaiting inspection state and are more than 3 months old.
  old_rmas_on_awaiting_inspection = Rma.where(state: 'awaiting_inspection').where('created_at < ?', three_months_old)
  if old_rmas_on_awaiting_inspection.present?
    old_rmas_on_awaiting_inspection.each do |rma|
      begin
        rma.void_all_items_and_self
      rescue StandardError => exc
        ErrorReporting.error exc, rma_id: rma.id
      end
    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)
  if old_rmas_on_requested.present?
    old_rmas_on_requested.each do |rma|
      begin
        rma.void_all_items_and_self
      rescue StandardError => exc
        ErrorReporting.error exc, rma_id: rma.id
      end
    end
  end
end