feat(movements): gate StockMovementLine on trackingType QUANTITY

This commit is contained in:
2026-06-25 03:22:08 +02:00
parent 8f7a406e83
commit a0a1e1bdc8
7 changed files with 257 additions and 16 deletions
+12 -10
View File
@@ -146,7 +146,7 @@ export async function createAssignmentUseCase(
return createAssignmentError({ itemId: ["Item not found"] })
}
if (item.stock < quantity) {
if (item.trackingType === "QUANTITY" && item.stock < quantity) {
return createAssignmentError({
quantity: ["Item does not have enough stock"],
})
@@ -166,16 +166,18 @@ export async function createAssignmentUseCase(
}
}
const stockWasDecremented = await ItemService.decrementStockIfAvailable(
itemId,
quantity,
tx,
)
if (item.trackingType === "QUANTITY") {
const stockWasDecremented = await ItemService.decrementStockIfAvailable(
itemId,
quantity,
tx,
)
if (!stockWasDecremented) {
return createAssignmentError({
quantity: ["Item does not have enough stock"],
})
if (!stockWasDecremented) {
return createAssignmentError({
quantity: ["Item does not have enough stock"],
})
}
}
if (assetId) {