Deals Excel import/export aligned with Didar: browser-side import, new deal fields (code, probability, closedAt, creator, lostNote, referrer), Didar custom fields

This commit is contained in:
2026-10-06 16:36:04 +03:30
parent e08f1452ef
commit 2a2728e5ee
11 changed files with 1032 additions and 210 deletions
@@ -0,0 +1,20 @@
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "code" TEXT;
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "importSource" TEXT NOT NULL DEFAULT 'manual';
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "sourceRef" TEXT;
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "probability" INTEGER;
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "sourceDetail" TEXT;
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "referrer" TEXT;
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "lostNote" TEXT;
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "closedAt" TIMESTAMP(3);
ALTER TABLE "Deal" ADD COLUMN IF NOT EXISTS "createdById" TEXT;
DO $$ BEGIN
ALTER TABLE "Deal" ADD CONSTRAINT "Deal_createdById_fkey" FOREIGN KEY ("createdById") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
EXCEPTION WHEN duplicate_object THEN NULL;
END $$;
CREATE INDEX IF NOT EXISTS "Deal_organizationId_sourceRef_idx" ON "Deal"("organizationId", "sourceRef");
UPDATE "Deal"
SET "importSource" = 'didar', "sourceRef" = "customFields"->>'didarId'
WHERE "sourceRef" IS NULL AND COALESCE("customFields"->>'didarId', '') <> '';
+19
View File
@@ -240,6 +240,7 @@ model User {
organization Organization @relation(fields: [organizationId], references: [id], onDelete: Cascade)
ownedDeals Deal[] @relation("DealOwner")
assignedDeals Deal[] @relation("DealAssignees")
createdDeals Deal[] @relation("DealCreator")
ownedQuotes Quote[] @relation("QuoteOwner")
ownedInvoices Invoice[] @relation("InvoiceOwner")
ownedPeople Person[] @relation("PersonOwner")
@@ -557,11 +558,26 @@ model Deal {
stageId String
stage PipelineStage @relation(fields: [stageId], references: [id], onDelete: Restrict)
title String
/// کد دستی معامله
code String?
/// منبع ورود: manual | didar | excel
importSource String @default("manual")
/// شناسه در مبدأ (کد دیدار معامله)
sourceRef String?
amount Decimal? @db.Decimal(18, 2)
currency String @default("IRR")
status DealStatus @default(open)
/// احتمال موفقیت (۰ تا ۱۰۰)
probability Int?
/// شیوه آشنایی
source String?
/// شیوه آشنایی دلخواه
sourceDetail String?
referrer String?
lostReason String?
lostNote String?
/// تاریخ انجام (موفق/ناموفق شدن)
closedAt DateTime?
notes String?
tags String[] @default([])
isStale Boolean @default(false)
@@ -574,6 +590,8 @@ model Deal {
company Company? @relation(fields: [companyId], references: [id], onDelete: SetNull)
ownerId String?
owner User? @relation("DealOwner", fields: [ownerId], references: [id], onDelete: SetNull)
createdById String?
createdBy User? @relation("DealCreator", fields: [createdById], references: [id], onDelete: SetNull)
assignees User[] @relation("DealAssignees")
position Int @default(0)
activities Activity[]
@@ -592,6 +610,7 @@ model Deal {
@@index([personId])
@@index([companyId])
@@index([ownerId])
@@index([organizationId, sourceRef])
}
model Activity {