Skip to content

Commit

Permalink
allow stock_location_id for shipment on Importer::Order
Browse files Browse the repository at this point in the history
  • Loading branch information
ccarruitero committed Jun 5, 2020
1 parent 822a71d commit 448d504
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/lib/spree/core/importer/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def self.create_shipments_from_params(shipments_hash, order)
shipments_hash.each do |target|
shipment = Shipment.new
shipment.tracking = target[:tracking]
shipment.stock_location = Spree::StockLocation.find_by(admin_name: target[:stock_location]) || Spree::StockLocation.find_by!(name: target[:stock_location])
shipment.stock_location = Spree::StockLocation.find_by(id: target[:stock_location_id]) ||
Spree::StockLocation.find_by(admin_name: target[:stock_location]) ||
Spree::StockLocation.find_by!(name: target[:stock_location])

inventory_units = target[:inventory_units] || []
inventory_units.each do |inventory_unit|
Expand Down
9 changes: 9 additions & 0 deletions core/spec/lib/spree/core/importer/order_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,15 @@ module Core
}.to raise_error ActiveRecord::RecordNotFound
end

it "accepts stock_location_id" do
params[:shipments_attributes][0][:stock_location] = nil
params[:shipments_attributes][0][:stock_location_id] = stock_location.id
order = Importer::Order.import(user, params)
shipment = order.shipments.first

expect(shipment.stock_location).to eq stock_location
end

context 'when completed_at and shipped_at present' do
let(:params) do
{
Expand Down

0 comments on commit 448d504

Please sign in to comment.