Skip to content
This repository has been archived by the owner on Feb 23, 2020. It is now read-only.

Commit

Permalink
Make sure order updates itself after shipment handlers run.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Dutil authored and Jeff Dutil committed Sep 15, 2014
1 parent caa5a1a commit 026c754
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion lib/spree/wombat/handler/add_shipment_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ def process
shipment.refresh_rates
shipment.save!

return response("Added shipment #{shipment.number} for order #{order.number}")
# Ensure Order shipment state and totals are updated.
# Note: we call update_shipment_state separately from update in case order is not in completed.
order.updater.update_shipment_state
order.updater.update

return response("Added shipment #{shipment.number} for order #{order.number}")
end

end
Expand Down
6 changes: 5 additions & 1 deletion lib/spree/wombat/handler/update_shipment_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def process
shipment.refresh_rates
shipment.save!

return response("Updated shipment #{shipment_number}")
# Ensure Order shipment state and totals are updated.
# Note: we call update_shipment_state separately from update in case order is not in completed.
shipment.order.updater.update_shipment_state
shipment.order.updater.update

return response("Updated shipment #{shipment_number}")
end

end
Expand Down
1 change: 1 addition & 0 deletions spec/lib/spree/wombat/handler/add_shipment_handler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module Wombat
external_id = message["shipment"]["id"]
expect(responder.summary).to match /Added shipment #{external_id} for order R154085346/
expect(responder.code).to eql 200
expect(order.reload.shipment_state).to eq 'partial'
end

it "will set the shipment id as the shipment number" do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module Wombat
responder = handler.process
expect(responder.summary).to eql "Updated shipment #{shipment.number}"
expect(responder.code).to eql 200
expect(order.reload.shipment_state).to eq 'pending'
end

context "with mismatching items in shipment" do
Expand Down

0 comments on commit 026c754

Please sign in to comment.