Class: Spree::StockTransfer

Inherits:
Base
  • Object
show all
Includes:
Metadata, NumberAsParam, NumberIdentifier, Webhooks::HasWebhooks
Defined in:
app/models/spree/stock_transfer.rb

Instance Method Summary collapse

Methods included from NumberAsParam

#to_param

Methods inherited from Base

belongs_to_required_by_default, for_store, has_many_inversing, json_api_columns, json_api_permitted_attributes, json_api_type, page, spree_base_scopes, spree_base_uniqueness_scope

Methods included from Preferences::Preferable

#clear_preferences, #default_preferences, #defined_preferences, #deprecated_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_deprecated, #preference_type, #set_preference

Instance Method Details

#destination_movementsObject



22
23
24
# File 'app/models/spree/stock_transfer.rb', line 22

def destination_movements
  find_stock_location_with_location_id(destination_location_id)
end

#receive(destination_location, variants) ⇒ Object

receive inventory from external vendor



40
41
42
# File 'app/models/spree/stock_transfer.rb', line 40

def receive(destination_location, variants)
  transfer(nil, destination_location, variants)
end

#source_movementsObject



18
19
20
# File 'app/models/spree/stock_transfer.rb', line 18

def source_movements
  find_stock_location_with_location_id(source_location_id)
end

#transfer(source_location, destination_location, variants) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/models/spree/stock_transfer.rb', line 26

def transfer(source_location, destination_location, variants)
  transaction do
    variants.each_pair do |variant, quantity|
      source_location&.unstock(variant, quantity, self)
      destination_location.restock(variant, quantity, self)

      self.source_location = source_location
      self.destination_location = destination_location
      save!
    end
  end
end