diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index 9bd02bd1a0..33e34f4ffd 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -15,7 +15,7 @@ module Spree has_many :adjustments, as: :adjustable, dependent: :destroy before_create :generate_shipment_number - after_save :ensure_correct_adjustment, :update_order + after_save :ensure_correct_adjustment, :update_adjustments attr_accessor :special_instructions alias_attribute :amount, :cost @@ -344,8 +344,14 @@ module Spree end end - def update_order - order.reload.update! + def update_adjustments + return unless cost_changed? && state != 'shipped' + + recalculate_adjustments + end + + def recalculate_adjustments + Spree::ItemAdjustments.new(self).update end end end diff --git a/spec/models/spree/shipment_spec.rb b/spec/models/spree/shipment_spec.rb index 7359921472..614711579f 100644 --- a/spec/models/spree/shipment_spec.rb +++ b/spec/models/spree/shipment_spec.rb @@ -423,13 +423,6 @@ describe Spree::Shipment do end end - context "update_order" do - it "should update order" do - expect(order).to receive_message_chain(:reload, :update!) - shipment.__send__(:update_order) - end - end - describe "#update_amounts" do it "persists the shipping cost from the shipping fee adjustment" do allow(shipment).to receive(:fee_adjustment) { double(:adjustment, amount: 10) } @@ -442,7 +435,7 @@ describe Spree::Shipment do context "after_save" do it "should run correct callbacks" do expect(shipment).to receive(:ensure_correct_adjustment) - expect(shipment).to receive(:update_order) + expect(shipment).to receive(:update_adjustments) shipment.run_callbacks(:save) end end