mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-04 02:31:33 +00:00
Remove Shipment#stock_location
This commit is contained in:
@@ -14,7 +14,7 @@ module Api
|
||||
def create
|
||||
variant = scoped_variant(params[:variant_id])
|
||||
quantity = params[:quantity].to_i
|
||||
@shipment = get_or_create_shipment(params[:stock_location_id])
|
||||
@shipment = @order.shipment || @order.shipments.create
|
||||
|
||||
@order.contents.add(variant, quantity, @shipment)
|
||||
|
||||
@@ -116,10 +116,6 @@ module Api
|
||||
variant
|
||||
end
|
||||
|
||||
def get_or_create_shipment(stock_location_id)
|
||||
@order.shipment || @order.shipments.create(stock_location_id:)
|
||||
end
|
||||
|
||||
def shipment_params
|
||||
return {} unless params.has_key? :shipment
|
||||
|
||||
|
||||
@@ -42,9 +42,7 @@ module Spree
|
||||
#
|
||||
# Returns an array of backordered inventory units as per a given stock item
|
||||
def self.backordered_for_stock_item(stock_item)
|
||||
backordered_per_variant(stock_item).select do |unit|
|
||||
unit.shipment.stock_location == stock_item.stock_location
|
||||
end
|
||||
backordered_per_variant(stock_item)
|
||||
end
|
||||
|
||||
def self.finalize_units!(inventory_units)
|
||||
|
||||
@@ -5,13 +5,11 @@ require 'ostruct'
|
||||
module Spree
|
||||
class Shipment < ApplicationRecord
|
||||
self.belongs_to_required_by_default = false
|
||||
self.ignored_columns += [:stock_location_id]
|
||||
|
||||
belongs_to :order, class_name: 'Spree::Order'
|
||||
belongs_to :address, class_name: 'Spree::Address'
|
||||
|
||||
# WIP: phasing out stock location, it's not used.
|
||||
belongs_to :stock_location, class_name: 'Spree::StockLocation', optional: true
|
||||
|
||||
has_many :shipping_rates, dependent: :delete_all
|
||||
has_many :shipping_methods, through: :shipping_rates
|
||||
has_many :state_changes, as: :stateful, dependent: :destroy
|
||||
@@ -303,11 +301,6 @@ module Spree
|
||||
!shipped? && !order.canceled?
|
||||
end
|
||||
|
||||
# Other code still calls this for convenience.
|
||||
def stock_location
|
||||
@stock_location ||= DefaultStockLocation.find_or_create
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def line_items
|
||||
|
||||
@@ -2,14 +2,10 @@
|
||||
|
||||
module Api
|
||||
class ShipmentSerializer < ActiveModel::Serializer
|
||||
attributes :id, :tracking, :number, :order_id, :cost, :shipped_at, :stock_location_name, :state
|
||||
attributes :id, :tracking, :number, :order_id, :cost, :shipped_at, :state
|
||||
|
||||
def order_id
|
||||
object.order.number
|
||||
end
|
||||
|
||||
def stock_location_name
|
||||
object.stock_location.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,5 +30,5 @@
|
||||
var order_number = '#{@order.number}';
|
||||
var shipments = [];
|
||||
- @order.shipments.each do |shipment|
|
||||
shipments.push(#{shipment.to_json(:root => false, :include => [:inventory_units, :stock_location]).html_safe});
|
||||
shipments.push(#{shipment.to_json(:root => false, :include => [:inventory_units]).html_safe});
|
||||
= render :partial => 'spree/admin/shared/update_order_state', :handlers => [:erb], :formats => [:js]
|
||||
|
||||
@@ -6,9 +6,7 @@ RSpec.describe Api::V0::ShipmentsController, type: :controller do
|
||||
render_views
|
||||
|
||||
let!(:shipment) { create(:shipment) }
|
||||
let!(:attributes) do
|
||||
[:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id]
|
||||
end
|
||||
let(:attributes) { %w[id tracking number cost shipped_at order_id] }
|
||||
let(:current_api_user) { build(:user) }
|
||||
|
||||
before do
|
||||
@@ -31,13 +29,11 @@ RSpec.describe Api::V0::ShipmentsController, type: :controller do
|
||||
let(:current_api_user) { build(:admin_user) }
|
||||
let!(:order) { shipment.order }
|
||||
let(:order_ship_address) { create(:address) }
|
||||
let!(:stock_location) { DefaultStockLocation.find_or_create }
|
||||
let!(:variant) { create(:variant) }
|
||||
let(:params) do
|
||||
{ quantity: 2,
|
||||
variant_id: variant.to_param,
|
||||
order_id: order.number,
|
||||
stock_location_id: stock_location.to_param,
|
||||
format: :json }
|
||||
end
|
||||
let(:error_message) { "broken shipments creation" }
|
||||
@@ -109,7 +105,7 @@ RSpec.describe Api::V0::ShipmentsController, type: :controller do
|
||||
allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true)
|
||||
api_put :ready, order_id: shipment.order.to_param, id: shipment.to_param
|
||||
|
||||
expect(attributes.all?{ |attr| json_response.key? attr.to_s }).to be_truthy
|
||||
expect(json_response.keys).to include(*attributes)
|
||||
expect(json_response["state"]).to eq("ready")
|
||||
expect(shipment.reload.state).to eq("ready")
|
||||
end
|
||||
@@ -120,7 +116,7 @@ RSpec.describe Api::V0::ShipmentsController, type: :controller do
|
||||
|
||||
api_put :ready, order_id: shipment.order.to_param, id: shipment.to_param
|
||||
|
||||
expect(attributes.all?{ |attr| json_response.key? attr.to_s }).to be_truthy
|
||||
expect(json_response.keys).to include(*attributes)
|
||||
expect(json_response["state"]).to eq("ready")
|
||||
expect(shipment.reload.state).to eq("ready")
|
||||
end
|
||||
@@ -324,7 +320,7 @@ RSpec.describe Api::V0::ShipmentsController, type: :controller do
|
||||
id: shipment.to_param,
|
||||
shipment: { tracking: "123123" }
|
||||
|
||||
expect(attributes.all?{ |attr| json_response.key? attr.to_s }).to be_truthy
|
||||
expect(json_response.keys).to include(*attributes)
|
||||
expect(json_response["state"]).to eq("shipped")
|
||||
end
|
||||
end
|
||||
@@ -424,7 +420,7 @@ RSpec.describe Api::V0::ShipmentsController, type: :controller do
|
||||
|
||||
def expect_valid_response
|
||||
expect(response.status).to eq 200
|
||||
attributes.all?{ |attr| json_response.key? attr.to_s }
|
||||
expect(json_response.keys).to include(*attributes)
|
||||
end
|
||||
|
||||
def make_order_contents_fail
|
||||
|
||||
@@ -11,7 +11,6 @@ FactoryBot.define do
|
||||
state { 'pending' }
|
||||
order
|
||||
address
|
||||
stock_location { DefaultStockLocation.find_or_create }
|
||||
|
||||
after(:create) do |shipment, _evalulator|
|
||||
shipment.add_shipping_method(create(:shipping_method), true)
|
||||
@@ -31,7 +30,6 @@ FactoryBot.define do
|
||||
state { 'pending' }
|
||||
order
|
||||
address
|
||||
stock_location { DefaultStockLocation.find_or_create }
|
||||
|
||||
trait :shipping_method do
|
||||
transient do
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
FactoryBot.define do
|
||||
factory :stock_package, class: OrderManagement::Stock::Package do
|
||||
transient do
|
||||
stock_location { build(:stock_location) }
|
||||
order { create(:order_with_line_items, line_items_count: 2) }
|
||||
contents { [] }
|
||||
end
|
||||
|
||||
@@ -11,7 +11,6 @@ RSpec.describe Spree::InventoryUnit do
|
||||
|
||||
let(:shipment) do
|
||||
shipment = Spree::Shipment.new
|
||||
shipment.stock_location = stock_location
|
||||
shipment.shipping_methods << create(:shipping_method)
|
||||
shipment.order = order
|
||||
# We don't care about this in this test
|
||||
|
||||
@@ -324,7 +324,6 @@ RSpec.describe Spree::Shipment do
|
||||
allow(shipment).to receive_message_chain(:inventory_units,
|
||||
:group_by,
|
||||
map: [unit])
|
||||
shipment.stock_location = build(:stock_location)
|
||||
expect(variant).to receive(:move).with(1, shipment)
|
||||
shipment.after_cancel
|
||||
end
|
||||
@@ -348,7 +347,6 @@ RSpec.describe Spree::Shipment do
|
||||
allow(shipment).to receive_message_chain(:inventory_units,
|
||||
:group_by,
|
||||
map: [unit])
|
||||
shipment.stock_location = create(:stock_location)
|
||||
expect(variant).to receive(:move).with(-1, shipment)
|
||||
shipment.after_resume
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user