mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-30 21:27:17 +00:00
Move shipping fee adjustment from the order to the shipment
This commit is contained in:
@@ -12,7 +12,7 @@ module Spree
|
||||
has_many :shipping_methods, through: :shipping_rates
|
||||
has_many :state_changes, as: :stateful
|
||||
has_many :inventory_units, dependent: :delete_all
|
||||
has_one :adjustment, as: :source, dependent: :destroy
|
||||
has_many :adjustments, as: :adjustable, dependent: :destroy
|
||||
|
||||
before_create :generate_shipment_number
|
||||
after_save :ensure_correct_adjustment, :update_order
|
||||
@@ -258,6 +258,10 @@ module Spree
|
||||
inventory_units.create(variant_id: variant.id, state: state, order_id: order.id)
|
||||
end
|
||||
|
||||
def adjustment
|
||||
@adjustment ||= adjustments.shipping.first
|
||||
end
|
||||
|
||||
def ensure_correct_adjustment
|
||||
if adjustment
|
||||
adjustment.originator = shipping_method
|
||||
@@ -267,7 +271,7 @@ module Spree
|
||||
adjustment.reload
|
||||
elsif selected_shipping_rate_id
|
||||
shipping_method.create_adjustment(shipping_method.adjustment_label,
|
||||
order,
|
||||
self,
|
||||
self,
|
||||
true,
|
||||
"open")
|
||||
|
||||
@@ -387,7 +387,7 @@ describe Spree::Shipment do
|
||||
it "should create adjustment when not present" do
|
||||
allow(shipment).to receive_messages(selected_shipping_rate_id: 1)
|
||||
expect(shipping_method).to receive(:create_adjustment).with(shipping_method.adjustment_label,
|
||||
order, shipment, true, "open")
|
||||
shipment, shipment, true, "open")
|
||||
shipment.__send__(:ensure_correct_adjustment)
|
||||
end
|
||||
|
||||
@@ -395,7 +395,7 @@ describe Spree::Shipment do
|
||||
it "should use the shipping method's adjustment label" do
|
||||
allow(shipment).to receive_messages(selected_shipping_rate_id: 1)
|
||||
allow(shipping_method).to receive_messages(adjustment_label: "Foobar")
|
||||
expect(shipping_method).to receive(:create_adjustment).with("Foobar", order,
|
||||
expect(shipping_method).to receive(:create_adjustment).with("Foobar", shipment,
|
||||
shipment, true, "open")
|
||||
shipment.__send__(:ensure_correct_adjustment)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user