diff --git a/lib/spree/wombat/handler/add_shipment_handler.rb b/lib/spree/wombat/handler/add_shipment_handler.rb index 61b9383..28f9e43 100644 --- a/lib/spree/wombat/handler/add_shipment_handler.rb +++ b/lib/spree/wombat/handler/add_shipment_handler.rb @@ -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 diff --git a/lib/spree/wombat/handler/update_shipment_handler.rb b/lib/spree/wombat/handler/update_shipment_handler.rb index 9244261..3fd7c40 100644 --- a/lib/spree/wombat/handler/update_shipment_handler.rb +++ b/lib/spree/wombat/handler/update_shipment_handler.rb @@ -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 diff --git a/spec/lib/spree/wombat/handler/add_shipment_handler_spec.rb b/spec/lib/spree/wombat/handler/add_shipment_handler_spec.rb index 19b561d..6d1d726 100644 --- a/spec/lib/spree/wombat/handler/add_shipment_handler_spec.rb +++ b/spec/lib/spree/wombat/handler/add_shipment_handler_spec.rb @@ -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 diff --git a/spec/lib/spree/wombat/handler/update_shipment_handler_spec.rb b/spec/lib/spree/wombat/handler/update_shipment_handler_spec.rb index c00204f..10316f2 100644 --- a/spec/lib/spree/wombat/handler/update_shipment_handler_spec.rb +++ b/spec/lib/spree/wombat/handler/update_shipment_handler_spec.rb @@ -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