Move #adjustment_label to shipment

This commit is contained in:
Matt-Yorkley
2021-02-14 14:05:29 +00:00
parent e67c29872a
commit c0b33de0f0
3 changed files with 9 additions and 18 deletions

View File

@@ -265,12 +265,12 @@ module Spree
def ensure_correct_adjustment
if adjustment
adjustment.originator = shipping_method
adjustment.label = shipping_method.adjustment_label
adjustment.label = adjustment_label
adjustment.amount = selected_shipping_rate.cost if adjustment.open?
adjustment.save!
adjustment.reload
elsif selected_shipping_rate_id
shipping_method.create_adjustment(shipping_method.adjustment_label,
shipping_method.create_adjustment(adjustment_label,
self,
self,
true,
@@ -282,6 +282,10 @@ module Spree
update_adjustment_included_tax if adjustment
end
def adjustment_label
I18n.t('shipping')
end
private
def manifest_unstock(item)

View File

@@ -54,10 +54,6 @@ module Spree
where("spree_shipping_methods.display_on is null OR spree_shipping_methods.display_on = ''")
}
def adjustment_label
I18n.t('shipping')
end
# Here we allow checkout with shipping methods without zones (see issue #3928 for details)
# and also checkout with addresses outside of the zones of the selected shipping method
# This method could be used, like in Spree, to validate shipping method zones on checkout.

View File

@@ -386,20 +386,11 @@ 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,
expect(shipping_method).to receive(:create_adjustment).with(shipment.adjustment_label,
shipment, shipment, true, "open")
shipment.__send__(:ensure_correct_adjustment)
end
# Regression test for #3138
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", shipment,
shipment, true, "open")
shipment.__send__(:ensure_correct_adjustment)
end
it "should update originator when adjustment is present" do
allow(shipment).
to receive_messages(selected_shipping_rate: Spree::ShippingRate.new(cost: 10.00))
@@ -407,7 +398,7 @@ describe Spree::Shipment do
allow(shipment).to receive_messages(adjustment: adjustment, update_columns: true)
allow(adjustment).to receive(:open?) { true }
expect(shipment.adjustment).to receive(:originator=).with(shipping_method)
expect(shipment.adjustment).to receive(:label=).with(shipping_method.adjustment_label)
expect(shipment.adjustment).to receive(:label=).with(shipment.adjustment_label)
expect(shipment.adjustment).to receive(:amount=).with(10.00)
allow(shipment.adjustment).to receive(:save!)
expect(shipment.adjustment).to receive(:reload)
@@ -421,7 +412,7 @@ describe Spree::Shipment do
allow(shipment).to receive_messages(adjustment: adjustment, update_columns: true)
allow(adjustment).to receive(:open?) { false }
expect(shipment.adjustment).to receive(:originator=).with(shipping_method)
expect(shipment.adjustment).to receive(:label=).with(shipping_method.adjustment_label)
expect(shipment.adjustment).to receive(:label=).with(shipment.adjustment_label)
expect(shipment.adjustment).not_to receive(:amount=).with(10.00)
allow(shipment.adjustment).to receive(:save!)
expect(shipment.adjustment).to receive(:reload)