From 448d504938d149a8d9273bcec36aaa3fa7b2a233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Carruitero?= Date: Fri, 5 Jun 2020 12:23:11 -0500 Subject: [PATCH] allow stock_location_id for shipment on Importer::Order --- core/lib/spree/core/importer/order.rb | 4 +++- core/spec/lib/spree/core/importer/order_spec.rb | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/lib/spree/core/importer/order.rb b/core/lib/spree/core/importer/order.rb index 002af23120b..8e05bf2689f 100644 --- a/core/lib/spree/core/importer/order.rb +++ b/core/lib/spree/core/importer/order.rb @@ -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| diff --git a/core/spec/lib/spree/core/importer/order_spec.rb b/core/spec/lib/spree/core/importer/order_spec.rb index a90c79e4edc..94a2a5f77f3 100644 --- a/core/spec/lib/spree/core/importer/order_spec.rb +++ b/core/spec/lib/spree/core/importer/order_spec.rb @@ -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 {