Class: Spree::StockTransfers::Create
- Defined in:
- app/workflows/spree/stock_transfers/create.rb
Overview
Plans a transfer. Nothing moves: a draft is a packing list the merchant can still edit, and stock only leaves the source warehouse when MarkInTransit runs.
Instance Attribute Summary collapse
-
#stock_transfer ⇒ Object
readonly
The created transfer — 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 Spree::ServiceModule::Base
Methods included from Workflow::ControlFlow
Instance Attribute Details
#stock_transfer ⇒ Object (readonly)
The created transfer — hook handlers read it (nil while :validate runs).
10 11 12 |
# File 'app/workflows/spree/stock_transfers/create.rb', line 10 def stock_transfer @stock_transfer end |
Instance Method Details
#perform(store:, source_location:, destination_location:, items: [], reference: nil, notes: nil, metadata: nil, created_by: nil) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/workflows/spree/stock_transfers/create.rb', line 21 def perform(store:, source_location:, destination_location:, items: [], reference: nil, notes: nil, metadata: nil, created_by: nil) super step :build_transfer run_hooks :validate ApplicationRecord.transaction do step :save_transfer end run_hooks :after_create # No `publish_event` here: `publishes_lifecycle_events` on the model # already emits `stock_transfer.created` after commit, and publishing # it again fires every subscriber and webhook twice. success(stock_transfer.reload) end |