Keep backorders when splitting part of variant to new shipment with same SL - #6319
Merged
Conversation
These are already overridden in all other first-level context blocks so it makes sense to move them in the single block that relies on these values.
Also, a couple of useless `let!` are removed (these records already exist).
The removed spec can be replaced by the shared example, which includes one further test so it slightly improves coverage.
This helps keeping things in sync just in the case that numbers change.
These specs don't really require a specific first level scenario, so we're first extracting them to a shared example, and with the following commit we're going to use it in other existing scenarios.
The existing scenario is reworked in order to expose an issue when moving a few items of a variant (not all of them) to a shipment with same stock location as the original one.
This is propedeutic for the following commit.
When the quantifier is initialized with a stock location or its ID, the new method returns the positive amount of stock on hand or zero, if the stock for the variant is negative. Otherwise, it returns nil.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6319 +/- ##
==========================================
+ Coverage 89.34% 89.35% +0.01%
==========================================
Files 961 961
Lines 20161 20186 +25
==========================================
+ Hits 18012 18037 +25
Misses 2149 2149 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jarednorman
approved these changes
Aug 26, 2025
tvdeyen
approved these changes
Sep 5, 2025
tvdeyen
left a comment
Member
There was a problem hiding this comment.
Thanks for taking on the work @adammathys
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rebased version of #5670, because GitHub won't let me push to that branch.
Closes #5670.