Do not update finalized fee adjustments

This commit is contained in:
Rob Harrington
2017-10-19 16:54:39 +11:00
parent cd744dab68
commit b7976a2356
2 changed files with 25 additions and 0 deletions

View File

@@ -144,6 +144,8 @@ Spree::Order.class_eval do
end
# After changing line items of a completed order
# TODO: perhaps this should be triggered from a controller
# rather than an after_save callback?
def update_shipping_fees!
shipments.each do |shipment|
next if shipment.shipped?
@@ -153,6 +155,8 @@ Spree::Order.class_eval do
end
# After changing line items of a completed order
# TODO: perhaps this should be triggered from a controller
# rather than an after_save callback?
def update_payment_fees!
payments.each do |payment|
next if payment.completed?
@@ -367,6 +371,7 @@ Spree::Order.class_eval do
end
def update_adjustment!(adjustment)
return if adjustment.finalized?
state = adjustment.state
adjustment.state = 'open'
adjustment.update!(self)

View File

@@ -687,6 +687,26 @@ describe Spree::Order do
expect(order.adjustment_total).to eq expected_fees - shipping_fee - payment_fee
expect(order.shipment.adjustment.included_tax).to eq 0.6
end
context "when finalized fee adjustments exist on the order" do
let(:payment_fee_adjustment) { order.adjustments.payment_fee.first }
let(:shipping_fee_adjustment) { order.adjustments.shipping.first }
before do
payment_fee_adjustment.finalize!
shipping_fee_adjustment.finalize!
order.reload
end
it "does not attempt to update such adjustments" do
order.update_attributes(line_items_attributes: [{id: order.line_items.first.id, quantity: 0}])
# Check if fees got updated
order.reload
expect(order.adjustment_total).to eq expected_fees
expect(order.shipment.adjustment.included_tax).to eq 1.2
end
end
end
context "changing the shipping method to one without fees" do