Skip to content

Keep backorders when splitting part of variant to new shipment with same SL - #6319

Merged
tvdeyen merged 10 commits into
mainfrom
spaghetticode/fix-issue-5669
Sep 5, 2025
Merged

Keep backorders when splitting part of variant to new shipment with same SL#6319
tvdeyen merged 10 commits into
mainfrom
spaghetticode/fix-issue-5669

Conversation

@adammathys

Copy link
Copy Markdown
Member

Summary

Rebased version of #5670, because GitHub won't let me push to that branch.

Fixes #5669

When splitting a shipment to the same stock location, when not the whole quantity for the variant is moved it may happen, if there are backordered items, that these disappear (they become on hand).

This PR first reworks and adds further coverage to specs for the Spree::FulfilmentChanger service to expose the issue, then addresses it in the last commit.

Closes #5670.

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.
@adammathys adammathys self-assigned this Aug 22, 2025
@adammathys
adammathys requested a review from a team as a code owner August 22, 2025 17:19
@github-actions github-actions Bot added the changelog:solidus_core Changes to the solidus_core gem label Aug 22, 2025
@codecov

codecov Bot commented Aug 22, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.35%. Comparing base (12f00d6) to head (5663477).
⚠️ Report is 17 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@tvdeyen tvdeyen added this to the 4.6 milestone Sep 5, 2025

@tvdeyen tvdeyen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking on the work @adammathys

@tvdeyen
tvdeyen merged commit 1f0a28f into main Sep 5, 2025
39 checks passed
@tvdeyen
tvdeyen deleted the spaghetticode/fix-issue-5669 branch September 5, 2025 15:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog:solidus_core Changes to the solidus_core gem

Projects

Development

Successfully merging this pull request may close these issues.

[Backend] Backordered items may become on hand when splitting shipment

4 participants