106 lines
5.3 KiB
Plaintext
106 lines
5.3 KiB
Plaintext
model B2bPartnerOrder {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
accountId String @map("account_id") @db.Uuid
|
|
quoteId String @map("quote_id") @db.Uuid
|
|
createdById String @map("created_by_id") @db.Uuid
|
|
number String @db.VarChar(24)
|
|
partnerReference String @map("partner_reference") @db.VarChar(80)
|
|
note String? @db.VarChar(500)
|
|
accountSnapshot Json @map("account_snapshot") @db.JsonB
|
|
currency String @db.Char(3)
|
|
merchandiseTotal Decimal @map("merchandise_total") @db.Decimal(18,2)
|
|
idempotencyKey String @map("idempotency_key") @db.Uuid
|
|
requestHash String @map("request_hash") @db.Char(64)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
|
|
account BusinessAccount @relation(fields: [accountId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
quote B2bQuote @relation(fields: [quoteId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
createdBy User @relation(fields: [createdById, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
lines B2bPartnerOrderLine[]
|
|
cancellation B2bPartnerOrderCancellation?
|
|
payments B2bPartnerPayment[]
|
|
@@unique([id, organizationId])
|
|
@@unique([organizationId, number])
|
|
@@unique([quoteId, organizationId])
|
|
@@unique([organizationId, accountId, partnerReference])
|
|
@@unique([organizationId, idempotencyKey])
|
|
@@index([organizationId, accountId, createdAt, id])
|
|
@@map("b2b_partner_orders")
|
|
}
|
|
|
|
model B2bPartnerOrderLine {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
orderId String @map("order_id") @db.Uuid
|
|
variantId String @map("variant_id") @db.Uuid
|
|
sku String @db.VarChar(64)
|
|
name String @db.VarChar(160)
|
|
quantity Int
|
|
minQuantity Int @map("min_quantity")
|
|
unitPrice Decimal @map("unit_price") @db.Decimal(12,2)
|
|
lineTotal Decimal @map("line_total") @db.Decimal(18,2)
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
|
|
order B2bPartnerOrder @relation(fields: [orderId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
variant ProductVariant @relation(fields: [variantId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
@@unique([orderId, variantId])
|
|
@@index([organizationId, orderId, id])
|
|
@@map("b2b_partner_order_lines")
|
|
}
|
|
|
|
model B2bPartnerOrderCancellation {
|
|
orderId String @id @map("order_id") @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
actorId String @map("actor_id") @db.Uuid
|
|
reason String @db.VarChar(500)
|
|
idempotencyKey String @map("idempotency_key") @db.Uuid
|
|
requestHash String @map("request_hash") @db.Char(64)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
|
|
order B2bPartnerOrder @relation(fields: [orderId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
actor User @relation(fields: [actorId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
@@unique([orderId, organizationId])
|
|
@@unique([organizationId, idempotencyKey])
|
|
@@map("b2b_partner_order_cancellations")
|
|
}
|
|
|
|
model B2bPartnerPayment {
|
|
id String @id @default(uuid()) @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
orderId String @map("order_id") @db.Uuid
|
|
recordedById String @map("recorded_by_id") @db.Uuid
|
|
reference String @db.VarChar(80)
|
|
method String @db.VarChar(20)
|
|
currency String @db.Char(3)
|
|
amount Decimal @db.Decimal(18,2)
|
|
receivedOn DateTime @map("received_on") @db.Date
|
|
idempotencyKey String @map("idempotency_key") @db.Uuid
|
|
requestHash String @map("request_hash") @db.Char(64)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
|
|
order B2bPartnerOrder @relation(fields: [orderId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
recordedBy User @relation(fields: [recordedById, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
reversal B2bPartnerPaymentReversal?
|
|
@@unique([id, organizationId])
|
|
@@unique([organizationId, idempotencyKey])
|
|
@@unique([organizationId, reference])
|
|
@@index([organizationId, orderId, createdAt, id])
|
|
@@map("b2b_partner_payments")
|
|
}
|
|
|
|
model B2bPartnerPaymentReversal {
|
|
paymentId String @id @map("payment_id") @db.Uuid
|
|
organizationId String @map("organization_id") @db.Uuid
|
|
reversedById String @map("reversed_by_id") @db.Uuid
|
|
reason String @db.VarChar(500)
|
|
idempotencyKey String @map("idempotency_key") @db.Uuid
|
|
requestHash String @map("request_hash") @db.Char(64)
|
|
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(3)
|
|
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Restrict)
|
|
payment B2bPartnerPayment @relation(fields: [paymentId, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
reversedBy User @relation(fields: [reversedById, organizationId], references: [id, organizationId], onDelete: Restrict)
|
|
@@unique([paymentId, organizationId])
|
|
@@unique([organizationId, idempotencyKey])
|
|
@@map("b2b_partner_payment_reversals")
|
|
}
|