Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove remnants of location configured packages #2270

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions api/app/controllers/spree/api/line_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ def create
@line_item = @order.contents.add(
variant,
params[:line_item][:quantity] || 1,
{
stock_location_quantities: params[:line_item][:stock_location_quantities]
}.merge({ options: line_item_params[:options].to_h })
options: line_item_params[:options].to_h
)

if @line_item.errors.empty?
Expand Down
2 changes: 0 additions & 2 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ def states
pluck(:state).uniq
end
end
has_many :order_stock_locations, class_name: "Spree::OrderStockLocation"
has_many :stock_locations, through: :order_stock_locations

# Adjustments and promotions
has_many :adjustments, -> { order(:created_at) }, as: :adjustable, inverse_of: :adjustable, dependent: :destroy
Expand Down
14 changes: 0 additions & 14 deletions core/app/models/spree/order_contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ def initialize(order)
# @param [Hash] :options Options for the adding proccess
# Valid options:
# shipment: [Spree::Shipment] LineItem target shipment
# stock_location_quantities:
# stock_location_id: The stock location to source from
#
# @return [Spree::LineItem]
def add(variant, quantity = 1, options = {})
Expand Down Expand Up @@ -98,10 +96,6 @@ def add_to_line_item(variant, quantity, options = {})
line_item.quantity += quantity.to_i
line_item.options = ActionController::Parameters.new(options).permit(PermittedAttributes.line_item_attributes).to_h

if line_item.new_record?
create_order_stock_locations(line_item, options[:stock_location_quantities])
end

line_item.target_shipment = options[:shipment]
line_item.save!
line_item
Expand Down Expand Up @@ -130,13 +124,5 @@ def grab_line_item_by_variant(variant, raise_error = false, options = {})

line_item
end

def create_order_stock_locations(line_item, stock_location_quantities)
return unless stock_location_quantities.present?
order = line_item.order
stock_location_quantities.each do |stock_location_id, quantity|
order.order_stock_locations.create!(stock_location_id: stock_location_id, quantity: quantity, variant_id: line_item.variant_id) unless quantity.to_i.zero?
end
end
end
end
5 changes: 0 additions & 5 deletions core/app/models/spree/order_shipping.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,13 @@ def ship(inventory_units:, stock_location:, address:, shipping_method:,
end

send_shipment_emails(carton) if stock_location.fulfillable? && !suppress_mailer # e.g. digital gift cards that aren't actually shipped
fulfill_order_stock_locations(stock_location)
@order.recalculate

carton
end

private

def fulfill_order_stock_locations(stock_location)
Spree::OrderStockLocation.fulfill_for_order_with_stock_location(@order, stock_location)
end

def send_shipment_emails(carton)
carton.orders.each do |order|
Spree::Config.carton_shipped_email_class.shipped_email(order: order, carton: carton).deliver_later
Expand Down
15 changes: 0 additions & 15 deletions core/app/models/spree/order_stock_location.rb

This file was deleted.

10 changes: 0 additions & 10 deletions core/db/migrate/20160101010000_solidus_one_four.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,16 +278,6 @@ def up
t.index ["order_id"], name: "index_spree_order_mutexes_on_order_id", unique: true
end

create_table "spree_order_stock_locations", force: :cascade do |t|
t.integer "order_id"
t.integer "variant_id"
t.integer "quantity"
t.integer "stock_location_id"
t.boolean "shipment_fulfilled", default: false, null: false
t.datetime "created_at"
t.datetime "updated_at"
end

create_table "spree_orders", force: :cascade do |t|
t.string "number", limit: 32
t.decimal "item_total", precision: 10, scale: 2, default: "0.0", null: false
Expand Down
8 changes: 0 additions & 8 deletions core/spec/models/spree/order_contents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,6 @@
expect(order.total.to_f).to eq(19.99)
end

it "should create stock location associations if provided" do
line_item = subject.add(variant, 3, stock_location_quantities: { stock_location.id => 1, stock_location_2.id => 2 })
order_stock_locations = line_item.order.order_stock_locations
expect(order_stock_locations.count).to eq(2)
expect(order_stock_locations.map(&:quantity)).to eq([1, 2])
expect(order_stock_locations.map(&:stock_location_id)).to eq([stock_location.id, stock_location_2.id])
end

context "running promotions" do
let(:promotion) { create(:promotion, apply_automatically: true) }
let(:calculator) { Spree::Calculator::FlatRate.new(preferred_amount: 10) }
Expand Down
18 changes: 0 additions & 18 deletions core/spec/models/spree/order_stock_location_spec.rb

This file was deleted.

8 changes: 0 additions & 8 deletions core/spec/models/spree/shipment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,6 @@
allow(shipment).to receive_messages(require_inventory: false, update_order: true, state: state)
end

it "should call fulfill_order_with_stock_location" do
expect(Spree::OrderStockLocation).to(
receive(:fulfill_for_order_with_stock_location).
with(order, stock_location)
)
shipment.ship!
end

it "finalizes adjustments" do
shipment.adjustments.each do |adjustment|
expect(adjustment).to receive(:finalize!)
Expand Down
23 changes: 0 additions & 23 deletions core/spec/models/spree/stock/simple_coordinator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,29 +184,6 @@ module Stock
let(:location_2_inventory) { 5 }
it_behaves_like "a fulfillable package"
end

context "with a location configured package" do
before do
order.order_stock_locations.create(
stock_location: stock_location_2,
quantity: 3,
variant: variant
)
end
let(:location_quantity) { 3 }

context "and sufficient inventory" do
let(:location_1_inventory) { 5 }
let(:location_2_inventory) { 5 }
it_behaves_like "a fulfillable package"
end

context "and insufficient inventory" do
let(:location_1_inventory) { 0 }
let(:location_2_inventory) { 3 }
it_behaves_like "an unfulfillable package"
end
end
end

context 'with three stock locations' do
Expand Down