Support for Adjusting incoming_quantity in Inventory Module #13718
lorenzo-polaris
started this conversation in
Feature Requests
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Problem Statement
Currently, the Inventory Module's
adjustInventory
method only supports adjusting thestocked_quantity
field. The key advantage of this method is that it performs the read and update operations atomically within a transaction, preventing race conditions when multiple processes attempt to adjust inventory simultaneously.However, the
incoming_quantity
field lacks this critical capability. Whileincoming_quantity
can be set directly viacreateInventoryLevels
andupdateInventoryLevels
, there is no way to atomically adjust (increment/decrement) the incoming quantity. Developers must:incoming_quantity
valueupdateInventoryLevels
with the new valueThis multi-step process introduces a race condition window between the read and write operations. In high-concurrency scenarios (e.g., multiple purchase orders being processed simultaneously, or concurrent inventory transfers), this can lead to lost updates, incorrect inventory counts, and data inconsistency.
Proposed Solution
Type Definition
Service Implementation (Pseudo-code)
Note: This is just a pseudo implementation to illustrate the concept. If the Medusa team approves this proposal, I will implement a production-ready version with proper error handling, validation, tests, and documentation.
Usage Examples
Would love to hear the Medusa team's thoughts on this proposal! If approved, I'm ready to implement a production-ready version with comprehensive tests and documentation.
Beta Was this translation helpful? Give feedback.
All reactions