Add a small internal warehouse and party balances when Tahesab is off.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -180,6 +180,9 @@ model Organization {
|
||||
noteAiSuggestions NoteAiSuggestion[]
|
||||
accountingConnections AccountingConnection[]
|
||||
accountingSyncJobs AccountingSyncJob[]
|
||||
warehouses Warehouse[]
|
||||
stockMovements StockMovement[]
|
||||
partyOpenings PartyOpeningBalance[]
|
||||
}
|
||||
|
||||
model User {
|
||||
@@ -283,6 +286,7 @@ model Person {
|
||||
memoryItems MemoryItem[]
|
||||
accountingLinks PersonAccountingLink[]
|
||||
accountingDocuments AccountingDocumentLog[]
|
||||
openingBalances PartyOpeningBalance[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -545,6 +549,7 @@ model Product {
|
||||
lineItems DealLineItem[]
|
||||
quoteLineItems QuoteLineItem[]
|
||||
invoiceLineItems InvoiceLineItem[]
|
||||
stockMovements StockMovement[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -725,6 +730,7 @@ model Invoice {
|
||||
lineItems InvoiceLineItem[]
|
||||
payments Payment[]
|
||||
installments InvoiceInstallment[]
|
||||
stockMovements StockMovement[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@ -1210,3 +1216,57 @@ model AccountingSyncJob {
|
||||
|
||||
@@index([organizationId, createdAt])
|
||||
}
|
||||
|
||||
/// انبار داخلی — وقتی تهحساب وصل نیست
|
||||
model Warehouse {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
name String
|
||||
isDefault Boolean @default(true)
|
||||
movements StockMovement[]
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@index([organizationId, isDefault])
|
||||
}
|
||||
|
||||
/// گردش کالا؛ مقدار مثبت ورود، منفی خروج
|
||||
model StockMovement {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
warehouseId String
|
||||
warehouse Warehouse @relation(fields: [warehouseId], references: [id], onDelete: Cascade)
|
||||
productId String
|
||||
product Product @relation(fields: [productId], references: [id], onDelete: Cascade)
|
||||
/// opening | purchase | sale | credit | adjustment
|
||||
type String
|
||||
quantity Decimal @db.Decimal(18, 2)
|
||||
note String?
|
||||
invoiceId String?
|
||||
invoice Invoice? @relation(fields: [invoiceId], references: [id], onDelete: Cascade)
|
||||
occurredAt DateTime @default(now())
|
||||
createdAt DateTime @default(now())
|
||||
|
||||
@@index([organizationId, productId, occurredAt])
|
||||
@@index([invoiceId])
|
||||
@@index([warehouseId])
|
||||
}
|
||||
|
||||
/// مانده اول دوره طرفحساب (مثبت = بدهکار ما)
|
||||
model PartyOpeningBalance {
|
||||
id String @id @default(cuid())
|
||||
organizationId String
|
||||
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
|
||||
personId String
|
||||
person Person @relation(fields: [personId], references: [id], onDelete: Cascade)
|
||||
amount Decimal @db.Decimal(18, 2)
|
||||
currency String @default("IRR")
|
||||
note String?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
|
||||
@@unique([organizationId, personId])
|
||||
@@index([personId])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user