Use shipping fee adjustment as single source of truth, and persist it on the shipment :cost field when it changes.

This commit is contained in:
Matt-Yorkley
2021-02-14 16:11:50 +00:00
parent bcbea618e8
commit f956aca82f
2 changed files with 5 additions and 12 deletions

View File

@@ -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

View File

@@ -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