inventory control
This commit is contained in:
@@ -28,6 +28,7 @@ model User {
|
||||
approvedSalesOrders SalesOrder[] @relation("SalesOrderApprovedBy")
|
||||
salesQuoteRevisionsCreated SalesQuoteRevision[] @relation("SalesQuoteRevisionCreatedBy")
|
||||
salesOrderRevisionsCreated SalesOrderRevision[] @relation("SalesOrderRevisionCreatedBy")
|
||||
inventoryTransfersCreated InventoryTransfer[] @relation("InventoryTransferCreatedBy")
|
||||
}
|
||||
|
||||
model Role {
|
||||
@@ -134,6 +135,8 @@ model InventoryItem {
|
||||
workOrders WorkOrder[]
|
||||
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
||||
operations InventoryItemOperation[]
|
||||
reservations InventoryReservation[]
|
||||
transfers InventoryTransfer[]
|
||||
}
|
||||
|
||||
model Warehouse {
|
||||
@@ -148,6 +151,9 @@ model Warehouse {
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
workOrders WorkOrder[]
|
||||
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
||||
reservations InventoryReservation[]
|
||||
transferSources InventoryTransfer[] @relation("InventoryTransferFromWarehouse")
|
||||
transferDestinations InventoryTransfer[] @relation("InventoryTransferToWarehouse")
|
||||
}
|
||||
|
||||
model Customer {
|
||||
@@ -216,6 +222,9 @@ model WarehouseLocation {
|
||||
purchaseReceipts PurchaseReceipt[]
|
||||
workOrders WorkOrder[]
|
||||
workOrderMaterialIssues WorkOrderMaterialIssue[]
|
||||
reservations InventoryReservation[]
|
||||
transferSourceLocations InventoryTransfer[] @relation("InventoryTransferFromLocation")
|
||||
transferDestinationLocations InventoryTransfer[] @relation("InventoryTransferToLocation")
|
||||
|
||||
@@unique([warehouseId, code])
|
||||
@@index([warehouseId])
|
||||
@@ -243,6 +252,51 @@ model InventoryTransaction {
|
||||
@@index([locationId, createdAt])
|
||||
}
|
||||
|
||||
model InventoryTransfer {
|
||||
id String @id @default(cuid())
|
||||
itemId String
|
||||
fromWarehouseId String
|
||||
fromLocationId String
|
||||
toWarehouseId String
|
||||
toLocationId String
|
||||
quantity Int
|
||||
notes String
|
||||
createdById String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
||||
fromWarehouse Warehouse @relation("InventoryTransferFromWarehouse", fields: [fromWarehouseId], references: [id], onDelete: Restrict)
|
||||
fromLocation WarehouseLocation @relation("InventoryTransferFromLocation", fields: [fromLocationId], references: [id], onDelete: Restrict)
|
||||
toWarehouse Warehouse @relation("InventoryTransferToWarehouse", fields: [toWarehouseId], references: [id], onDelete: Restrict)
|
||||
toLocation WarehouseLocation @relation("InventoryTransferToLocation", fields: [toLocationId], references: [id], onDelete: Restrict)
|
||||
createdBy User? @relation("InventoryTransferCreatedBy", fields: [createdById], references: [id], onDelete: SetNull)
|
||||
|
||||
@@index([itemId, createdAt])
|
||||
}
|
||||
|
||||
model InventoryReservation {
|
||||
id String @id @default(cuid())
|
||||
itemId String
|
||||
warehouseId String?
|
||||
locationId String?
|
||||
workOrderId String?
|
||||
sourceType String
|
||||
sourceId String?
|
||||
quantity Int
|
||||
status String @default("ACTIVE")
|
||||
notes String
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
item InventoryItem @relation(fields: [itemId], references: [id], onDelete: Cascade)
|
||||
warehouse Warehouse? @relation(fields: [warehouseId], references: [id], onDelete: SetNull)
|
||||
location WarehouseLocation? @relation(fields: [locationId], references: [id], onDelete: SetNull)
|
||||
workOrder WorkOrder? @relation(fields: [workOrderId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@index([itemId, status, createdAt])
|
||||
@@index([warehouseId, locationId, status])
|
||||
@@index([workOrderId, status])
|
||||
}
|
||||
|
||||
model Vendor {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
@@ -480,6 +534,7 @@ model WorkOrder {
|
||||
operations WorkOrderOperation[]
|
||||
materialIssues WorkOrderMaterialIssue[]
|
||||
completions WorkOrderCompletion[]
|
||||
reservations InventoryReservation[]
|
||||
|
||||
@@index([itemId, createdAt])
|
||||
@@index([projectId, dueDate])
|
||||
|
||||
Reference in New Issue
Block a user