Class: Spree::Claims::Create

Inherits:
Workflow show all
Includes:
Refunds::TaxCredit
Defined in:
app/workflows/spree/claims/create.rb

Overview

Opens a claim: the customer reports a problem with what arrived.

No goods come back — that is the point of a claim — so there is nothing to receive and nothing to restock.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Workflow

#call, define_argument_readers, #errors, #halt!, hooks, inherited, model_name, #read_attribute_for_validation, #reject!, workflow_key

Methods included from ServiceModule::Base

#call, prepended

Methods included from Workflow::ControlFlow

#failure

Instance Attribute Details

#claim ⇒ Object (readonly)

Returns the value of attribute claim.



12
13
14
# File 'app/workflows/spree/claims/create.rb', line 12

def claim
  @claim
end

Instance Method Details

#perform(order:, items:, reason: nil, memo: nil, created_by: nil) ⇒ Object

Parameters:

  • order (Spree::Order)
  • items (Array<Hash>) —

    [{ line_item:, quantity:, description:, send_replacement:, replacement_variant:, refund_amount: }]

  • reason (Spree::ClaimReason, nil) (defaults to: nil)
  • memo (String, nil) (defaults to: nil)
  • created_by (Object, nil) (defaults to: nil) —

    nil for customer self-service



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/workflows/spree/claims/create.rb', line 20

def perform(order:, items:, reason: nil, memo: nil, created_by: nil)
  super

  step :ensure_claimable
  step :normalize_items
  run_hooks :validate

  ApplicationRecord.transaction do
    step :build_claim
    step :calculate_tax
    step :ensure_refunds_within_paid
  end

  run_hooks :after_create
  claim.publish_event('claim.opened')
  success(claim.reload)
end