Implement sales tenant pipeline events
This commit is contained in:
@@ -1,11 +1,96 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from sqlalchemy import Boolean, Float, Index, Integer, String, Text
|
||||
from sqlalchemy import Boolean, Float, Index, Integer, String, Text, UniqueConstraint, text
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from services.shared.sql_models import Base
|
||||
|
||||
|
||||
class TenantSalesSettingsRow(Base):
|
||||
__tablename__ = "tenant_sales_settings"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
default_pipeline_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
default_language: Mapped[str] = mapped_column(String(16), default="ru", index=True)
|
||||
default_currency: Mapped[str] = mapped_column(String(16), default="KZT", index=True)
|
||||
enabled_text_channels_json: Mapped[str] = mapped_column(Text, default="[]")
|
||||
enabled_voice_channels_json: Mapped[str] = mapped_column(Text, default="[]")
|
||||
payment_provider_settings_json: Mapped[str] = mapped_column(Text, default="{}")
|
||||
document_settings_json: Mapped[str] = mapped_column(Text, default="{}")
|
||||
created_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
updated_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
|
||||
|
||||
class TenantIntegrationRow(Base):
|
||||
__tablename__ = "tenant_integrations"
|
||||
__table_args__ = (
|
||||
Index("idx_tenant_integrations_provider_account", "provider_type", "provider_name", "provider_account_id"),
|
||||
Index("idx_tenant_integrations_external_identifier", "provider_type", "provider_name", "external_identifier"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
integration_id: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
provider_type: Mapped[str] = mapped_column(String(64), index=True)
|
||||
provider_name: Mapped[str] = mapped_column(String(64), index=True)
|
||||
provider_account_id: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
||||
external_identifier: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True)
|
||||
settings_json: Mapped[str] = mapped_column(Text, default="{}")
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
created_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
updated_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
|
||||
|
||||
class SalesPipelineRow(Base):
|
||||
__tablename__ = "sales_pipelines"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("tenant_id", "code", name="uq_sales_pipelines_tenant_code"),
|
||||
Index("idx_sales_pipelines_tenant_default", "tenant_id", "is_default", "is_active"),
|
||||
Index(
|
||||
"uq_sales_pipelines_one_default_per_tenant",
|
||||
"tenant_id",
|
||||
unique=True,
|
||||
sqlite_where=text("is_default = 1"),
|
||||
postgresql_where=text("is_default IS TRUE"),
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
pipeline_id: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
code: Mapped[str] = mapped_column(String(64), index=True)
|
||||
name: Mapped[str] = mapped_column(String(256))
|
||||
description: Mapped[str | None] = mapped_column(Text, nullable=True)
|
||||
is_default: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
created_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
updated_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
|
||||
|
||||
class SalesPipelineStageRow(Base):
|
||||
__tablename__ = "sales_pipeline_stages"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("tenant_id", "pipeline_id", "code", name="uq_sales_pipeline_stages_tenant_pipeline_code"),
|
||||
Index("idx_sales_pipeline_stages_pipeline_order", "tenant_id", "pipeline_id", "sort_order"),
|
||||
Index("idx_sales_pipeline_stages_tenant_active", "tenant_id", "is_active"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
stage_id: Mapped[str] = mapped_column(String(64), unique=True, index=True)
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
pipeline_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
code: Mapped[str] = mapped_column(String(64), index=True)
|
||||
name: Mapped[str] = mapped_column(String(256))
|
||||
category: Mapped[str] = mapped_column(String(64), index=True)
|
||||
sort_order: Mapped[int] = mapped_column(Integer, default=0, index=True)
|
||||
is_terminal: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
||||
is_system: Mapped[bool] = mapped_column(Boolean, default=False, index=True)
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, default=True, index=True)
|
||||
created_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
updated_at: Mapped[str] = mapped_column(String(64), index=True)
|
||||
|
||||
|
||||
class SalesLeadRow(Base):
|
||||
__tablename__ = "sales_leads"
|
||||
__table_args__ = (
|
||||
@@ -50,7 +135,7 @@ class SalesDealRow(Base):
|
||||
tenant_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
lead_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
customer_id: Mapped[str | None] = mapped_column(String(64), nullable=True, index=True)
|
||||
pipeline_id: Mapped[str] = mapped_column(String(64), default="sales_default", index=True)
|
||||
pipeline_id: Mapped[str] = mapped_column(String(64), default="", index=True)
|
||||
stage_id: Mapped[str] = mapped_column(String(64), index=True)
|
||||
scenario_type: Mapped[str] = mapped_column(String(64), index=True)
|
||||
priority: Mapped[int] = mapped_column(Integer, default=3, index=True)
|
||||
|
||||
Reference in New Issue
Block a user