Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Rename create_proposed_shipments to create_proposed_fulfillments

Damian Legawiecc252c0b08493
diff --git a/spree/core/app/models/spree/cart.rb b/spree/core/app/models/spree/cart.rb
index 10abe8401d..c22a7713d4 100644
--- a/spree/core/app/models/spree/cart.rb
+++ b/spree/core/app/models/spree/cart.rb
@@ -269,7 +269,7 @@ module Spree
end
# Idempotent delivery-proposal rebuild — replaces the destructive
- # order-side create_proposed_shipments. Open fulfillments are rebuilt from
+ # order-side create_proposed_fulfillments. Open fulfillments are rebuilt from
# the current items/address; nothing here touches a completed cart.
def rebuild_fulfillments!
return if completed?
@@ -326,7 +326,13 @@ module Spree
updater.persist_totals
end
alias set_shipments_cost set_fulfillments_cost
- alias create_proposed_shipments rebuild_fulfillments!
+ alias create_proposed_fulfillments rebuild_fulfillments!
+
+ # @deprecated Use {#create_proposed_fulfillments}; removed in 6.1.
+ def create_proposed_shipments
+ Spree::Deprecation.warn('Spree::Cart#create_proposed_shipments is deprecated and will be removed in Spree 6.1. Use #create_proposed_fulfillments instead.')
+ rebuild_fulfillments!
+ end
def ensure_updated_shipments
rebuild_fulfillments! unless completed?
diff --git a/spree/core/app/models/spree/order.rb b/spree/core/app/models/spree/order.rb
index 9af889172a..f3f4acbfab 100644
--- a/spree/core/app/models/spree/order.rb
+++ b/spree/core/app/models/spree/order.rb
@@ -834,7 +834,7 @@ module Spree
fully_fulfilled?
end
- def create_proposed_shipments
+ def create_proposed_fulfillments
discounts.for_fulfillments.delete_all
tax_lines.for_fulfillments.delete_all
fees.for_fulfillments.delete_all
@@ -854,6 +854,12 @@ module Spree
end
end
+ # @deprecated Use {#create_proposed_fulfillments}; removed in 6.1.
+ def create_proposed_shipments
+ Spree::Deprecation.warn('Spree::Order#create_proposed_shipments is deprecated and will be removed in Spree 6.1. Use #create_proposed_fulfillments instead.')
+ create_proposed_fulfillments
+ end
+
# Resolves the routing strategy from the channel override first, then the
# store default. Only a registered Spree::OrderRouting::Strategy::Base
# subclass is used; any other value (an unregistered/typo'd class, or a
diff --git a/spree/core/app/models/spree/order_inventory.rb b/spree/core/app/models/spree/order_inventory.rb
index fb9947363e..bdfd2469d1 100644
--- a/spree/core/app/models/spree/order_inventory.rb
+++ b/spree/core/app/models/spree/order_inventory.rb
@@ -101,7 +101,7 @@ module Spree
def add_to_shipment(shipment, quantity)
if shipment.nil?
- shipment = order.create_proposed_shipments.first
+ shipment = order.create_proposed_fulfillments.first
elsif variant.should_track_inventory?
on_hand, back_order = shipment.stock_location.fill_status(variant, quantity)
diff --git a/spree/core/app/services/spree/carts/update.rb b/spree/core/app/services/spree/carts/update.rb
index 85ba0f1ffb..a7ec5b6ab3 100644
--- a/spree/core/app/services/spree/carts/update.rb
+++ b/spree/core/app/services/spree/carts/update.rb
@@ -135,8 +135,8 @@ module Spree
cart.recalculate_for_address_change!
else
cart.ensure_updated_shipments
- if cart.ship_address.present? && cart.respond_to?(:create_proposed_shipments)
- cart.create_proposed_shipments
+ if cart.ship_address.present? && cart.respond_to?(:create_proposed_fulfillments)
+ cart.create_proposed_fulfillments
cart.set_shipments_cost
end
cart.update_with_updater!
diff --git a/spree/core/app/services/spree/checkout/get_shipping_rates.rb b/spree/core/app/services/spree/checkout/get_shipping_rates.rb
index 97dc6b1569..84fe7eb0f4 100644
--- a/spree/core/app/services/spree/checkout/get_shipping_rates.rb
+++ b/spree/core/app/services/spree/checkout/get_shipping_rates.rb
@@ -36,7 +36,7 @@ module Spree
def generate_shipping_rates(order:)
ApplicationRecord.transaction do
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
order.create_shipment_tax_charge!
order.set_shipments_cost
order.apply_free_shipping_promotions
diff --git a/spree/core/app/services/spree/orders/build_shipments.rb b/spree/core/app/services/spree/orders/build_shipments.rb
index fdbaeeddec..6e7d17f357 100644
--- a/spree/core/app/services/spree/orders/build_shipments.rb
+++ b/spree/core/app/services/spree/orders/build_shipments.rb
@@ -17,7 +17,7 @@ module Spree
return success(order) unless order.line_items.any?
return success(order) unless order.delivery_required?
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
order.create_shipment_tax_charge!
order.set_shipments_cost
order.apply_free_shipping_promotions
diff --git a/spree/core/db/sample_data/orders.rb b/spree/core/db/sample_data/orders.rb
index ab1914515e..08341c0f62 100644
--- a/spree/core/db/sample_data/orders.rb
+++ b/spree/core/db/sample_data/orders.rb
@@ -76,7 +76,7 @@ unless orders[1].line_items.any?
).save!
end
-orders.each(&:create_proposed_shipments)
+orders.each(&:create_proposed_fulfillments)
Spree::Order.where(id: orders.map(&:id)).update_all(status: 'placed', completed_at: Time.current - 1.day)
diff --git a/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb b/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb
index eae3d1ccf9..4374ea11a9 100644
--- a/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb
+++ b/spree/core/spec/models/spree/calculator/shipping/digital_delivery_spec.rb
@@ -31,7 +31,7 @@ RSpec.describe Spree::Calculator::Shipping::DigitalDelivery do
package = Spree::Stock::Package.new(create(:stock_location), [])
variants.each do |v|
add_line_item_to_order(order, v, 1)
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
package.add(order.inventory_units.where(variant_id: v.id).first, 1)
end
package
@@ -44,7 +44,7 @@ RSpec.describe Spree::Calculator::Shipping::DigitalDelivery do
package = Spree::Stock::Package.new(create(:stock_location), [])
variants.each do |v|
add_line_item_to_order(order, v, 1)
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
package.add(order.inventory_units.where(variant_id: v.id).first, 1)
end
package
@@ -56,7 +56,7 @@ RSpec.describe Spree::Calculator::Shipping::DigitalDelivery do
package = Spree::Stock::Package.new(create(:stock_location), [])
variants.each do |v|
add_line_item_to_order(order, v, 1)
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
package.add(order.inventory_units.where(variant_id: v.id).first, 1)
end
package
diff --git a/spree/core/spec/models/spree/delivery_method_rule_spec.rb b/spree/core/spec/models/spree/delivery_method_rule_spec.rb
index 216cf75715..6bf25128c9 100644
--- a/spree/core/spec/models/spree/delivery_method_rule_spec.rb
+++ b/spree/core/spec/models/spree/delivery_method_rule_spec.rb
@@ -59,7 +59,7 @@ describe Spree::DeliveryMethodRule, type: :model do
it 'drops ineligible methods from rate estimation' do
fulfillment = order.fulfillments.first || begin
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
order.fulfillments.first
end
method = fulfillment.refresh_rates.map(&:delivery_method).first
@@ -74,7 +74,7 @@ describe Spree::DeliveryMethodRule, type: :model do
end
it 'keeps methods whose rules pass' do
- order.create_proposed_shipments if order.fulfillments.none?
+ order.create_proposed_fulfillments if order.fulfillments.none?
fulfillment = order.fulfillments.first
method = fulfillment.refresh_rates.map(&:delivery_method).first
@@ -87,7 +87,7 @@ describe Spree::DeliveryMethodRule, type: :model do
end
it 'ignores inactive rules' do
- order.create_proposed_shipments if order.fulfillments.none?
+ order.create_proposed_fulfillments if order.fulfillments.none?
fulfillment = order.fulfillments.first
method = fulfillment.refresh_rates.map(&:delivery_method).first
diff --git a/spree/core/spec/models/spree/line_item_spec.rb b/spree/core/spec/models/spree/line_item_spec.rb
index 8d11770570..83a3f59885 100644
--- a/spree/core/spec/models/spree/line_item_spec.rb
+++ b/spree/core/spec/models/spree/line_item_spec.rb
@@ -376,7 +376,7 @@ describe Spree::LineItem, type: :model do
before do
variant.stock_items.update_all count_on_hand: 5, backorderable: false
Spree::Carts::AddItem.call(order: order, variant: variant, quantity: 5)
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
order.finalize!
order.reload
end
@@ -405,7 +405,7 @@ describe Spree::LineItem, type: :model do
before do
variant.stock_items.update_all count_on_hand: 7, backorderable: false
Spree::Carts::AddItem.call(order: order, variant: variant, quantity: 5)
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
order.finalize!
order.reload
end
diff --git a/spree/core/spec/models/spree/order/adjustments_spec.rb b/spree/core/spec/models/spree/order/adjustments_spec.rb
index d131eac1ed..7f0ffffe7f 100644
--- a/spree/core/spec/models/spree/order/adjustments_spec.rb
+++ b/spree/core/spec/models/spree/order/adjustments_spec.rb
@@ -14,7 +14,7 @@ describe Spree::Order do
before do
persisted_order.line_items << line_item
persisted_order.update!(ship_address: create(:address))
- persisted_order.create_proposed_shipments
+ persisted_order.create_proposed_fulfillments
persisted_order.set_shipments_cost
create(:discount, order: persisted_order, line_item: line_item, amount: -line_item.amount, label: 'Promotion', kind: 'manual')
persisted_order.update_with_updater!
@@ -57,7 +57,7 @@ describe Spree::Order do
before do
order.line_items << line_item
order.ship_address = address
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
order.send :ensure_available_shipping_rates
order.set_shipments_cost
order.create_shipment_tax_charge!
diff --git a/spree/core/spec/models/spree/order_spec.rb b/spree/core/spec/models/spree/order_spec.rb
index 21d287deb3..ded27d1918 100644
--- a/spree/core/spec/models/spree/order_spec.rb
+++ b/spree/core/spec/models/spree/order_spec.rb
@@ -1119,7 +1119,7 @@ describe Spree::Order, type: :model do
context 'when order has shipments and is not completed' do
before do
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
end
it 'destroys all shipments' do
@@ -1405,7 +1405,7 @@ describe Spree::Order, type: :model do
end
end
- describe '#create_proposed_shipments' do
+ describe '#create_proposed_fulfillments' do
context 'has unassociated inventory units' do
let!(:inventory_unit) { create(:inventory_unit, order: subject) }
@@ -1419,7 +1419,7 @@ describe Spree::Order, type: :model do
end
it 'does not delete inventory_unit' do
- subject.create_proposed_shipments
+ subject.create_proposed_fulfillments
expect(inventory_unit.reload).to eq inventory_unit
end
end
@@ -1430,7 +1430,7 @@ describe Spree::Order, type: :model do
end
it 'does not delete inventory_unit' do
- subject.create_proposed_shipments
+ subject.create_proposed_fulfillments
expect(inventory_unit.reload).to eq inventory_unit
end
end
@@ -1441,7 +1441,7 @@ describe Spree::Order, type: :model do
end
it 'deletes inventory_unit' do
- subject.create_proposed_shipments
+ subject.create_proposed_fulfillments
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -1452,7 +1452,7 @@ describe Spree::Order, type: :model do
end
it 'deletes inventory_unit' do
- subject.create_proposed_shipments
+ subject.create_proposed_fulfillments
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -1467,7 +1467,7 @@ describe Spree::Order, type: :model do
allow(strategy).to receive(:for_allocation).and_return([package])
allow(subject).to receive(:order_routing_strategy).and_return(strategy)
- subject.create_proposed_shipments
+ subject.create_proposed_fulfillments
expect(subject.fulfillments).to eq [shipment]
end
end
@@ -2280,6 +2280,17 @@ describe Spree::Order, type: :model do
end
end
+ describe '#create_proposed_shipments' do
+ it 'delegates to #create_proposed_fulfillments with a deprecation warning' do
+ order = create(:order)
+
+ expect(Spree::Deprecation).to receive(:warn).with(/create_proposed_fulfillments/)
+ expect(order).to receive(:create_proposed_fulfillments)
+
+ order.create_proposed_shipments
+ end
+ end
+
describe '#fully_shipped?' do
subject { order.fully_shipped? }
@@ -2676,7 +2687,7 @@ describe Spree::Order, type: :model do
physical_line_item
digital_line_item
order.update_with_updater!
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
expect(order.shipments.count).to eq(2)
diff --git a/spree/core/spec/models/spree/shipment_spec.rb b/spree/core/spec/models/spree/shipment_spec.rb
index cb0ab2d283..93e85c3422 100644
--- a/spree/core/spec/models/spree/shipment_spec.rb
+++ b/spree/core/spec/models/spree/shipment_spec.rb
@@ -380,7 +380,7 @@ describe Spree::Shipment, type: :model do
let(:order) { Spree::Order.create }
let(:variant) { create(:variant) }
let!(:line_item) { Spree::Carts::AddItem.call(order: order, variant: variant).value }
- let!(:shipment) { order.create_proposed_shipments.first }
+ let!(:shipment) { order.create_proposed_fulfillments.first }
it 'returns variant expected' do
expect(shipment.manifest.first.variant).to eq variant
@@ -675,10 +675,10 @@ describe Spree::Shipment, type: :model do
before do
Spree::Carts::AddItem.call(order: order, variant: variant)
- order.create_proposed_shipments
+ order.create_proposed_fulfillments
Spree::Carts::AddItem.call(order: other_order, variant: variant)
- other_order.create_proposed_shipments
+ other_order.create_proposed_fulfillments
end
it "doesn't fill backorders when restocking inventory units" do