Class: Spree::StockTransfer
- Inherits:
-
Base
- Object
- ActiveRecord::Base
- Base
- Spree::StockTransfer
show all
- Extended by:
- FriendlyId
- Includes:
- NumberGenerator
- Defined in:
- app/models/spree/stock_transfer.rb
Constant Summary
NumberGenerator::NUMBER_LENGTH, NumberGenerator::NUMBER_LETTERS, NumberGenerator::NUMBER_PREFIX
Instance Method Summary
collapse
by_number
Methods inherited from Base
page
#clear_preferences, #default_preferences, #defined_preferences, #get_preference, #has_preference!, #has_preference?, #preference_default, #preference_type, #set_preference
Instance Method Details
#destination_movements ⇒ Object
27
28
29
30
|
# File 'app/models/spree/stock_transfer.rb', line 27
def destination_movements
stock_movements.joins(:stock_item)
.where('spree_stock_items.stock_location_id' => destination_location_id)
end
|
#generate_number(options = {}) ⇒ Object
8
9
10
11
|
# File 'app/models/spree/stock_transfer.rb', line 8
def generate_number(options = {})
options[:prefix] ||= 'T'
super(options)
end
|
#receive(destination_location, variants) ⇒ Object
45
46
47
|
# File 'app/models/spree/stock_transfer.rb', line 45
def receive(destination_location, variants)
transfer(nil, destination_location, variants)
end
|
#source_movements ⇒ Object
22
23
24
25
|
# File 'app/models/spree/stock_transfer.rb', line 22
def source_movements
stock_movements.joins(:stock_item)
.where('spree_stock_items.stock_location_id' => source_location_id)
end
|
#to_param ⇒ Object
18
19
20
|
# File 'app/models/spree/stock_transfer.rb', line 18
def to_param
number
end
|
#transfer(source_location, destination_location, variants) ⇒ Object
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'app/models/spree/stock_transfer.rb', line 32
def transfer(source_location, destination_location, variants)
transaction do
variants.each_pair do |variant, quantity|
source_location.unstock(variant, quantity, self) if source_location
destination_location.restock(variant, quantity, self)
self.source_location = source_location
self.destination_location = destination_location
self.save!
end
end
end
|