Class: Spree::StockTransfer
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Spree::StockTransfer
- Defined in:
- app/models/spree/stock_transfer.rb
Instance Method Summary collapse
- #destination_movements ⇒ Object
- #receive(destination_location, variants) ⇒ Object
- #source_movements ⇒ Object
- #to_param ⇒ Object
- #transfer(source_location, destination_location, variants) ⇒ Object
Instance Method Details
#destination_movements ⇒ Object
19 20 21 22 |
# File 'app/models/spree/stock_transfer.rb', line 19 def destination_movements stock_movements.joins(:stock_item) .where('spree_stock_items.stock_location_id' => destination_location_id) end |
#receive(destination_location, variants) ⇒ Object
37 38 39 |
# File 'app/models/spree/stock_transfer.rb', line 37 def receive(destination_location, variants) transfer(nil, destination_location, variants) end |
#source_movements ⇒ Object
14 15 16 17 |
# File 'app/models/spree/stock_transfer.rb', line 14 def source_movements stock_movements.joins(:stock_item) .where('spree_stock_items.stock_location_id' => source_location_id) end |
#to_param ⇒ Object
10 11 12 |
# File 'app/models/spree/stock_transfer.rb', line 10 def to_param number end |
#transfer(source_location, destination_location, variants) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/models/spree/stock_transfer.rb', line 24 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 |