Improved update_shipment_state code

* added check for unassigned inventory for order shipment status
* rewrote the code to make less DB requests

Fixes #2246