# @description: # @author: licanglong # @date: 2025/12/22 20:12 from datetime import date, datetime from decimal import Decimal from sqlalchemy import ( String, Integer, Date, DateTime, Numeric, Index, ) from sqlalchemy.orm import Mapped, mapped_column from app.db.base import Base class InvoicePurchaseDetail(Base): """ 进项发票-信息汇总表 """ __tablename__ = "invoice_purchase_detail" # ======================= # 主键 # ======================= id: Mapped[int] = mapped_column( Integer, primary_key=True, autoincrement=True, comment="自增主键", ) tax_id: Mapped[str] = mapped_column( String(20), primary_key=True, comment="购方税号", ) # ======================= # 发票基础信息 # ======================= zzfpdm: Mapped[str] = mapped_column( String(32), nullable=False, default="", comment="发票代码", ) zzfphm: Mapped[str] = mapped_column( String(32), nullable=False, comment="发票号码", ) kprq: Mapped[date] = mapped_column( Date, nullable=False, comment="开票日期", ) # ======================= # 销方信息 # ======================= gmfmc: Mapped[str] = mapped_column( String(128), nullable=False, comment="销方名称", ) gmfnsrsbh: Mapped[str] = mapped_column( String(32), nullable=False, comment="销方税号", ) # ======================= # 商品 / 劳务信息 # ======================= ssflbm: Mapped[str | None] = mapped_column( String(32), nullable=True, comment="税收分类编码", ) tdywlx: Mapped[str | None] = mapped_column( String(32), nullable=True, comment="特定业务类型", ) hwmc: Mapped[str | None] = mapped_column( String(255), nullable=True, comment="货物或应税劳务名称", ) easy_hwmc: Mapped[str | None] = mapped_column( String(255), nullable=True, comment="货物名称", ) ggxh: Mapped[str | None] = mapped_column( String(128), nullable=True, comment="规格型号", ) dw: Mapped[str | None] = mapped_column( String(16), nullable=True, comment="计量单位名称", ) dw_symbol: Mapped[str | None] = mapped_column( String(16), nullable=True, comment="计量单位符号", ) # ======================= # 金额 / 数量 # ======================= xssl: Mapped[Decimal] = mapped_column( Numeric(24, 6), nullable=False, default=Decimal("0.000000"), comment="数量", ) dj: Mapped[Decimal] = mapped_column( Numeric(24, 8), nullable=False, default=Decimal("0.00000000"), comment="单价", ) hjje: Mapped[Decimal] = mapped_column( Numeric(10, 2), nullable=False, default=Decimal("0.00"), comment="金额", ) sl: Mapped[str | None] = mapped_column( String(6), nullable=True, comment="税率", ) hjse: Mapped[Decimal] = mapped_column( Numeric(10, 2), nullable=False, default=Decimal("0.00"), comment="税额", ) jshj: Mapped[Decimal] = mapped_column( Numeric(10, 2), nullable=False, default=Decimal("0.00"), comment="价税合计", ) # ======================= # 发票状态 / 风控相关 # ======================= fplydm: Mapped[str] = mapped_column( String(128), nullable=False, comment="发票来源", ) fppzdm: Mapped[str] = mapped_column( String(128), nullable=False, comment="发票票种", ) fpztdm: Mapped[str] = mapped_column( String(128), nullable=False, comment="发票状态", ) sflzfp: Mapped[str] = mapped_column( String(128), nullable=False, comment="发票风险等级", ) kpr: Mapped[str] = mapped_column( String(64), nullable=False, comment="开票人", ) # ======================= # 时间字段 # ======================= created_at: Mapped[datetime] = mapped_column( DateTime, nullable=False, default=datetime.utcnow, comment="创建时间", ) # ======================= # 索引定义 # ======================= __table_args__ = ( Index( "uni_hm_dm_taxid", "zzfphm", "zzfpdm", "tax_id", ), ) def __repr__(self) -> str: return ( f"" )