Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inventory): update reservation quantity #10139

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-spies-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@medusajs/inventory": patch
---

Update reservation quantity
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,15 @@ moduleIntegrationTestRunner<IInventoryService>({
const updated = await service.updateReservationItems(update)

expect(updated).toEqual(expect.objectContaining(update))

const update2 = {
id: reservationItem.id,
quantity: 10,
}

const updated2 = await service.updateReservationItems(update2)

expect(updated2).toEqual(expect.objectContaining(update2))
})

it("should adjust reserved_quantity of inventory level after updates increasing reserved quantity", async () => {
Expand Down Expand Up @@ -438,7 +447,7 @@ moduleIntegrationTestRunner<IInventoryService>({
it("should throw error when increasing reserved quantity beyond availability", async () => {
const update = {
id: reservationItem.id,
quantity: 10,
quantity: 11,
}

const error = await service
Expand Down
10 changes: 9 additions & 1 deletion packages/modules/inventory/src/services/inventory-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,18 @@ export default class InventoryModuleService
const availabilityData = input.map((data) => {
const reservation = reservationMap.get(data.id)!

let adjustment = data.quantity
? MathBN.sub(data.quantity, reservation.quantity)
: 0

if (MathBN.lt(adjustment, 0)) {
adjustment = 0
}

return {
inventory_item_id: reservation.inventory_item_id,
location_id: data.location_id ?? reservation.location_id,
quantity: data.quantity ?? reservation.quantity,
quantity: adjustment,
allow_backorder:
data.allow_backorder || reservation.allow_backorder || false,
}
Expand Down
Loading