mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-06 02:51:34 +00:00
Use Spree::ItemAdjustments in Shipment callbacks for updating adjustments
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user