diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 305dfba81b..2348bbc733 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -161,10 +161,8 @@ module Spree end def update_amounts - return unless selected_shipping_rate - - self.update_columns( - cost: selected_shipping_rate.cost, + update_columns( + cost: adjustment&.amount || 0.0, updated_at: Time.zone.now ) end @@ -278,7 +276,7 @@ module Spree reload # ensure adjustment is present on later saves end - update_amounts if adjustment + update_amounts if adjustment&.amount != cost update_adjustment_included_tax if adjustment end diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb index 255d1d8833..111aa43bcf 100644 --- a/spec/models/spree/shipment_spec.rb +++ b/spec/models/spree/shipment_spec.rb @@ -428,17 +428,12 @@ describe Spree::Shipment do end describe "#update_amounts" do - it "updates shipping cost when selected_shipping_rate is present" do - allow(shipment).to receive(:selected_shipping_rate) { double(:rate, cost: 10) } + it "persists the shipping cost from the shipping fee adjustment" do + allow(shipment).to receive(:adjustment) { double(:adjustment, amount: 10) } expect(shipment).to receive(:update_columns).with(cost: 10, updated_at: kind_of(Time)) shipment.update_amounts end - - it "does nothing when selected_shipping_rate is not present" do - expect(shipment).to_not receive(:update_columns) - shipment.update_amounts - end end context "after_save" do