Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly calculate inventory item quantities to be moved
The backordered quantity count should differ depending on whether moving to the same or a different stock location. For this reason, the way we calculate `available_quantity` changes as follows: * when the stock location differs: the stock on hand at the new shipment stock location; * when the stock location is the same: the sum of the stock on hand at the shipment stock location plus the number of on_hand inventory items from the shipment The explicit `backordered_quantity` variable is introduced to track the number of backordered items for the target shipment. The value is calculated as follows: * when the stock location differs: the quantity to be moved minus the positive available quantity at the stock location; * when the stock location is the same: the shipment total quantity for the variant minus the positive available quantity at the stock location. Also, we start the process by moving backordered items first to to make sure no pending backordered item remains. If the backordered count decreased, we're going to leave a few to be later moved and transformed to on hand, while if the backordered count increased, we are going to move also some previously on hand items.
- Loading branch information