""" 科目映射模型 存储标准字段到会计科目的映射关系 """ from typing import Optional from sqlalchemy import ForeignKey, Integer, String, Float, Boolean, JSON from sqlalchemy.orm import Mapped, mapped_column, relationship from app.models.base import BaseModel class AccountMapping(BaseModel): """ 科目映射模型 将标准字段(如基本工资、社保等)映射到会计科目 Attributes: company_id: 企业ID standard_field: 标准字段名 debit_account: 借方科目代码 debit_account_name: 借方科目名称 credit_account: 贷方科目代码 credit_account_name: 贷方科目名称 cost_center: 成本中心(可选) is_active: 是否启用 """ __tablename__ = "account_mappings" company_id: Mapped[int] = mapped_column(Integer, ForeignKey("companies.id"), nullable=False, index=True) standard_field: Mapped[str] = mapped_column(String(100), nullable=False, index=True, comment="标准字段名") debit_account: Mapped[str] = mapped_column(String(50), nullable=False, comment="借方科目代码") debit_account_name: Mapped[str] = mapped_column(String(200), nullable=False, comment="借方科目名称") credit_account: Mapped[str] = mapped_column(String(50), nullable=False, comment="贷方科目代码") credit_account_name: Mapped[str] = mapped_column(String(200), nullable=False, comment="贷方科目名称") cost_center: Mapped[Optional[str]] = mapped_column(String(100), nullable=True, comment="成本中心") is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True, comment="是否启用") # 关系 company = relationship("Company", backref="account_mappings") def __repr__(self) -> str: return f""