feat(items): emit ISSUE/ADJUSTMENT movement on stock decrease

This commit is contained in:
2026-06-25 03:03:26 +02:00
parent 0d38626f3a
commit 575cd2d9a0
4 changed files with 153 additions and 2 deletions
+13
View File
@@ -128,6 +128,7 @@ export async function updateItemUseCase(
status,
minStock,
targetStock,
reason,
} = input
try {
@@ -170,6 +171,18 @@ export async function updateItemUseCase(
},
tx,
)
} else if (updatedStock < existingItem.stock) {
const isInventoryCorrection = reason === "INVENTORY_CORRECTION"
await MovementService.create(
{
type: isInventoryCorrection ? "ADJUSTMENT" : "OUT",
itemId: id,
quantity: existingItem.stock - updatedStock,
stockDeltaSign: isInventoryCorrection ? -1 : undefined,
userId: actorId,
},
tx,
)
}
return {