mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-13 23:37:47 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user