Cleanup of #5166

This improves the quality of some of the code introduced in b252e9adcd02b5b0f0f89cdcfae583e72ae12fb7.

Of note this:
* Fixes some spurious failures due to postgresql ordering
* Raises exceptions from `transfer_to_location` and `transfer_to_shipment` rather than returning `[bool, string]`

I believe all tests are still passing.