Class: Edi::Amazon::ReturnsReportRmaMatch

Inherits:
Object
  • Object
show all
Defined in:
app/services/edi/amazon/returns_report_rma_match.rb

Overview

Verifies that a Merchant RMA ID belongs to the reported Amazon order's
internal return lineage.

Most RMAs point directly at the Amazon order. A replacement order created
from an earlier RMA points back through +orders.rma_id+ instead, and can
itself acquire a later RMA. Walking that canonical chain accepts those
descendants without treating an unrelated order as a match.

Instance Method Summary collapse

Constructor Details

#initialize(order:, rma:) ⇒ ReturnsReportRmaMatch

Returns a new instance of ReturnsReportRmaMatch.

Parameters:

  • order (Order)

    order found from the report's Amazon Order ID.

  • rma (Rma)

    RMA found from the report's Merchant RMA ID.



14
15
16
17
# File 'app/services/edi/amazon/returns_report_rma_match.rb', line 14

def initialize(order:, rma:)
  @order = order
  @rma = rma
end

Instance Method Details

#verified?Boolean

Returns whether the RMA belongs to the order or one of its
RMA-generated replacement orders.

Returns:

  • (Boolean)

    whether the RMA belongs to the order or one of its
    RMA-generated replacement orders.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/services/edi/amazon/returns_report_rma_match.rb', line 21

def verified?
  return false unless @order && @rma
  return true if @rma.original_order_id == @order.id

  current_order = @rma.original_order
  visited_order_ids = {}
  while current_order && !visited_order_ids[current_order.id]
    return true if current_order.id == @order.id

    visited_order_ids[current_order.id] = true
    current_order = current_order.rma&.original_order
  end
  false
end