fix(core-flows, dashboard): adjust stock levels when doing partial fulfilments (#9736)
* fix: correctly update stock location when partial fulfillemnt is created * fix: update test * fix: count reserved quantity of the item as available quantity for fulfillment * fix: refresh reservations when order fulfillment is created * feat: add check for reservation quantity * feat: add a test case
This commit is contained in:
@@ -202,20 +202,27 @@ function prepareInventoryUpdate({
|
||||
|
||||
const inputQuantity = inputItemsMap[item.id]?.quantity ?? item.quantity
|
||||
|
||||
const quantity = reservation.quantity - inputQuantity
|
||||
if (MathBN.gt(inputQuantity, reservation.quantity)) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
`Quantity to fulfill exceeds the reserved quantity for the item: ${item.id}`
|
||||
)
|
||||
}
|
||||
|
||||
const remainingReservationQuantity = reservation.quantity - inputQuantity
|
||||
|
||||
inventoryAdjustment.push({
|
||||
inventory_item_id: reservation.inventory_item_id,
|
||||
location_id: input.location_id ?? reservation.location_id,
|
||||
adjustment: MathBN.mult(item.quantity, -1),
|
||||
adjustment: MathBN.mult(inputQuantity, -1),
|
||||
})
|
||||
|
||||
if (quantity === 0) {
|
||||
if (remainingReservationQuantity === 0) {
|
||||
toDelete.push(reservation.id)
|
||||
} else {
|
||||
toUpdate.push({
|
||||
id: reservation.id,
|
||||
quantity: quantity,
|
||||
quantity: remainingReservationQuantity,
|
||||
location_id: input.location_id ?? reservation.location_id,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user