Add Phase 16 Chart of Accounts and ledger group intelligence
This commit is contained in:
@@ -0,0 +1,138 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from sqlalchemy import (
|
||||
DateTime,
|
||||
Float,
|
||||
ForeignKey,
|
||||
Integer,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.core.db.common import CommonBase
|
||||
|
||||
|
||||
class AccountingChartSyncRun(CommonBase):
|
||||
__tablename__ = "accounting_chart_sync_runs"
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
tenant_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("tenants.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
client_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("clients.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
tally_guid: Mapped[str] = mapped_column(String(120), nullable=False, index=True)
|
||||
company_name: Mapped[str] = mapped_column(String(255), nullable=False, default="")
|
||||
status: Mapped[str] = mapped_column(String(30), nullable=False, default="completed", index=True)
|
||||
group_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
ledger_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
classified_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
review_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
requested_by_user_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
created_at_utc: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
index=True,
|
||||
)
|
||||
|
||||
|
||||
class AccountingChartGroup(CommonBase):
|
||||
__tablename__ = "accounting_chart_groups"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"tenant_id",
|
||||
"client_id",
|
||||
"tally_guid",
|
||||
"name",
|
||||
name="uq_accounting_chart_group_name",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
tenant_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("tenants.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
client_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("clients.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
tally_guid: Mapped[str] = mapped_column(String(120), nullable=False, index=True)
|
||||
company_name: Mapped[str] = mapped_column(String(255), nullable=False, default="")
|
||||
master_guid: Mapped[str] = mapped_column(String(120), nullable=False, default="", index=True)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
|
||||
parent_name: Mapped[str] = mapped_column(String(255), nullable=False, default="", index=True)
|
||||
root_group_name: Mapped[str] = mapped_column(String(255), nullable=False, default="", index=True)
|
||||
depth: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
reserved_name: Mapped[str] = mapped_column(String(255), nullable=False, default="")
|
||||
is_revenue: Mapped[str] = mapped_column(String(30), nullable=False, default="")
|
||||
is_deemed_positive: Mapped[str] = mapped_column(String(30), nullable=False, default="")
|
||||
source_payload_json: Mapped[str] = mapped_column(Text, nullable=False, default="{}")
|
||||
synced_at_utc: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
index=True,
|
||||
)
|
||||
|
||||
|
||||
class AccountingChartLedger(CommonBase):
|
||||
__tablename__ = "accounting_chart_ledgers"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"tenant_id",
|
||||
"client_id",
|
||||
"tally_guid",
|
||||
"name",
|
||||
name="uq_accounting_chart_ledger_name",
|
||||
),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True, autoincrement=True)
|
||||
tenant_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("tenants.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
client_id: Mapped[int] = mapped_column(
|
||||
ForeignKey("clients.id", ondelete="CASCADE"), nullable=False, index=True
|
||||
)
|
||||
tally_guid: Mapped[str] = mapped_column(String(120), nullable=False, index=True)
|
||||
company_name: Mapped[str] = mapped_column(String(255), nullable=False, default="")
|
||||
master_guid: Mapped[str] = mapped_column(String(120), nullable=False, default="", index=True)
|
||||
name: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
|
||||
parent_group_name: Mapped[str] = mapped_column(String(255), nullable=False, default="", index=True)
|
||||
root_group_name: Mapped[str] = mapped_column(String(255), nullable=False, default="", index=True)
|
||||
|
||||
opening_balance: Mapped[float] = mapped_column(Float, nullable=False, default=0)
|
||||
closing_balance: Mapped[float] = mapped_column(Float, nullable=False, default=0)
|
||||
is_billwise_on: Mapped[str] = mapped_column(String(30), nullable=False, default="")
|
||||
tax_type: Mapped[str] = mapped_column(String(80), nullable=False, default="")
|
||||
gst_applicable: Mapped[str] = mapped_column(String(80), nullable=False, default="")
|
||||
gst_registration_type: Mapped[str] = mapped_column(String(80), nullable=False, default="")
|
||||
gst_type_of_supply: Mapped[str] = mapped_column(String(80), nullable=False, default="")
|
||||
hsn_code: Mapped[str] = mapped_column(String(40), nullable=False, default="")
|
||||
party_gstin: Mapped[str] = mapped_column(String(20), nullable=False, default="", index=True)
|
||||
|
||||
suggested_role_code: Mapped[str] = mapped_column(String(50), nullable=False, default="REVIEW", index=True)
|
||||
suggested_confidence: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
||||
suggestion_reason: Mapped[str] = mapped_column(Text, nullable=False, default="")
|
||||
|
||||
manual_role_code: Mapped[str] = mapped_column(String(50), nullable=False, default="", index=True)
|
||||
manual_note: Mapped[str] = mapped_column(Text, nullable=False, default="")
|
||||
manual_by_user_id: Mapped[int | None] = mapped_column(
|
||||
ForeignKey("users.id", ondelete="SET NULL"), nullable=True
|
||||
)
|
||||
manual_at_utc: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
||||
|
||||
source_payload_json: Mapped[str] = mapped_column(Text, nullable=False, default="{}")
|
||||
synced_at_utc: Mapped[datetime] = mapped_column(
|
||||
DateTime(timezone=True),
|
||||
nullable=False,
|
||||
default=lambda: datetime.now(timezone.utc),
|
||||
index=True,
|
||||
)
|
||||
Reference in New Issue
Block a user