Class: Spree::Returns::Create
- Includes:
- Spree::Refunds::TaxCredit, ReturnableQuantity
- Defined in:
- app/workflows/spree/returns/create.rb
Overview
Opens a return request for fulfilled items on a completed order.
The validate hook is the seam for return-eligibility policy —
30-day windows, final-sale categories, per-customer-group rules,
regional consumer rights. That policy is the most-customized rule in
commerce and deliberately does not live in core.
Instance Attribute Summary collapse
-
#return_record ⇒ Object
readonly
The created return — hook handlers read it (nil while :validate runs).
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
Methods included from Workflow::ControlFlow
Instance Attribute Details
#return_record ⇒ Object (readonly)
The created return — hook handlers read it (nil while :validate runs).
16 17 18 |
# File 'app/workflows/spree/returns/create.rb', line 16 def return_record @return_record end |
Instance Method Details
#perform(order:, items:, stock_location: nil, reason: nil, memo: nil, created_by: nil) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/workflows/spree/returns/create.rb', line 26 def perform(order:, items:, stock_location: nil, reason: nil, memo: nil, created_by: nil) super step :ensure_returnable step :normalize_items # Veto point — return-window and eligibility policy. Before anything # is written. run_hooks :validate # The tax is worked out with the return rather than after it, so no # return ever offers a refund whose tax nobody calculated. ApplicationRecord.transaction do step :build_return step :calculate_tax end run_hooks :after_create return_record.publish_event('return.requested') success(return_record.reload) end |