52 lines
2.7 KiB
Python
52 lines
2.7 KiB
Python
from __future__ import annotations
|
|
|
|
from datetime import date, datetime, timezone
|
|
|
|
from sqlalchemy import BigInteger, Boolean, Date, DateTime, ForeignKey, Integer, String, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column
|
|
|
|
from app.core.db.common import CommonBase
|
|
|
|
|
|
def _utcnow() -> datetime:
|
|
return datetime.now(timezone.utc)
|
|
|
|
|
|
class AccountingMirrorRegistry(CommonBase):
|
|
"""Authoritative link between one ERP client/FY and its active local .act mirror."""
|
|
|
|
__tablename__ = "accounting_mirror_registry"
|
|
__table_args__ = (
|
|
UniqueConstraint(
|
|
"tenant_id",
|
|
"client_id",
|
|
"financial_year",
|
|
name="uq_accounting_mirror_registry_client_fy",
|
|
),
|
|
)
|
|
|
|
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)
|
|
storage_node_id: Mapped[int | None] = mapped_column(ForeignKey("branch_storage_nodes.id", ondelete="SET NULL"), nullable=True, index=True)
|
|
|
|
financial_year: Mapped[str] = mapped_column(String(7), nullable=False, index=True)
|
|
accounting_relative_dir: Mapped[str] = mapped_column(String(1000), nullable=False)
|
|
mirror_file_name: Mapped[str] = mapped_column(String(255), nullable=False)
|
|
|
|
company_name: Mapped[str] = mapped_column(String(255), nullable=False, default="")
|
|
company_guid: Mapped[str] = mapped_column(String(160), nullable=False, default="")
|
|
voucher_from_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
voucher_to_date: Mapped[date | None] = mapped_column(Date, nullable=True)
|
|
file_size_bytes: Mapped[int] = mapped_column(BigInteger, nullable=False, default=0)
|
|
|
|
status: Mapped[str] = mapped_column(String(30), nullable=False, default="active", index=True)
|
|
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, index=True)
|
|
replacement_count: Mapped[int] = mapped_column(Integer, nullable=False, default=0)
|
|
|
|
created_by_user_id: Mapped[int | None] = mapped_column(ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
|
last_synced_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=_utcnow)
|
|
last_synced_at_utc: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), nullable=True)
|
|
updated_at_utc: Mapped[datetime] = mapped_column(DateTime(timezone=True), nullable=False, default=_utcnow, onupdate=_utcnow)
|