feat(items): emit ISSUE/ADJUSTMENT movement on stock decrease
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user