Skip to content

Commit

Permalink
Source location in Stock Transfer should be optional
Browse files Browse the repository at this point in the history
Since Rails 5 there is a presence validation for belongs_to by default.

In this case however there are possible of Stock Transfers from vendors
to store stock location
  • Loading branch information
damianlegawiec committed Mar 3, 2018
1 parent 166e32b commit 747e4bd
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/app/models/spree/stock_transfer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class StockTransfer < Spree::Base

has_many :stock_movements, as: :originator

belongs_to :source_location, class_name: 'StockLocation'
belongs_to :source_location, class_name: 'StockLocation', optional: true
belongs_to :destination_location, class_name: 'StockLocation'

validates :number, uniqueness: true
Expand Down Expand Up @@ -36,6 +36,7 @@ def transfer(source_location, destination_location, variants)
end
end

# receive inventory from external vendor
def receive(destination_location, variants)
transfer(nil, destination_location, variants)
end
Expand Down

0 comments on commit 747e4bd

Please sign in to comment.