fix(inventory): update reservation quantity (#10139)
This commit is contained in:
1 parent
d933b3f1e4
commit
47ca1d4b54
3 files changed
+24
-2
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@medusajs/inventory": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Update reservation quantity
|
||||||
+10
-1
@@ -399,6 +399,15 @@ moduleIntegrationTestRunner<IInventoryService>({
|
|||||||
const updated = await service.updateReservationItems(update)
|
const updated = await service.updateReservationItems(update)
|
||||||
|
|
||||||
expect(updated).toEqual(expect.objectContaining(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 () => {
|
it("should adjust reserved_quantity of inventory level after updates increasing reserved quantity", async () => {
|
||||||
@@ -438,7 +447,7 @@ moduleIntegrationTestRunner<IInventoryService>({
|
|||||||
it("should throw error when increasing reserved quantity beyond availability", async () => {
|
it("should throw error when increasing reserved quantity beyond availability", async () => {
|
||||||
const update = {
|
const update = {
|
||||||
id: reservationItem.id,
|
id: reservationItem.id,
|
||||||
quantity: 10,
|
quantity: 11,
|
||||||
}
|
}
|
||||||
|
|
||||||
const error = await service
|
const error = await service
|
||||||
|
|||||||
@@ -746,10 +746,18 @@ export default class InventoryModuleService
|
|||||||
const availabilityData = input.map((data) => {
|
const availabilityData = input.map((data) => {
|
||||||
const reservation = reservationMap.get(data.id)!
|
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 {
|
return {
|
||||||
inventory_item_id: reservation.inventory_item_id,
|
inventory_item_id: reservation.inventory_item_id,
|
||||||
location_id: data.location_id ?? reservation.location_id,
|
location_id: data.location_id ?? reservation.location_id,
|
||||||
quantity: data.quantity ?? reservation.quantity,
|
quantity: adjustment,
|
||||||
allow_backorder:
|
allow_backorder:
|
||||||
data.allow_backorder || reservation.allow_backorder || false,
|
data.allow_backorder || reservation.allow_backorder || false,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user