invoice_do.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. # @description:
  2. # @author: licanglong
  3. # @date: 2025/12/22 20:12
  4. from datetime import date, datetime
  5. from decimal import Decimal
  6. from sqlalchemy import (
  7. String,
  8. Integer,
  9. Date,
  10. DateTime,
  11. Numeric, Index,
  12. )
  13. from sqlalchemy.orm import Mapped, mapped_column
  14. from app.db.base import Base
  15. class InvoicePurchaseDetail(Base):
  16. """
  17. 进项发票-信息汇总表
  18. """
  19. __tablename__ = "invoice_purchase_detail"
  20. # =======================
  21. # 主键
  22. # =======================
  23. id: Mapped[int] = mapped_column(
  24. Integer,
  25. primary_key=True,
  26. autoincrement=True,
  27. comment="自增主键",
  28. )
  29. tax_id: Mapped[str] = mapped_column(
  30. String(20),
  31. primary_key=True,
  32. comment="购方税号",
  33. )
  34. # =======================
  35. # 发票基础信息
  36. # =======================
  37. zzfpdm: Mapped[str] = mapped_column(
  38. String(32),
  39. nullable=False,
  40. default="",
  41. comment="发票代码",
  42. )
  43. zzfphm: Mapped[str] = mapped_column(
  44. String(32),
  45. nullable=False,
  46. comment="发票号码",
  47. )
  48. kprq: Mapped[date] = mapped_column(
  49. Date,
  50. nullable=False,
  51. comment="开票日期",
  52. )
  53. # =======================
  54. # 销方信息
  55. # =======================
  56. gmfmc: Mapped[str] = mapped_column(
  57. String(128),
  58. nullable=False,
  59. comment="销方名称",
  60. )
  61. gmfnsrsbh: Mapped[str] = mapped_column(
  62. String(32),
  63. nullable=False,
  64. comment="销方税号",
  65. )
  66. # =======================
  67. # 商品 / 劳务信息
  68. # =======================
  69. ssflbm: Mapped[str | None] = mapped_column(
  70. String(32),
  71. nullable=True,
  72. comment="税收分类编码",
  73. )
  74. tdywlx: Mapped[str | None] = mapped_column(
  75. String(32),
  76. nullable=True,
  77. comment="特定业务类型",
  78. )
  79. hwmc: Mapped[str | None] = mapped_column(
  80. String(255),
  81. nullable=True,
  82. comment="货物或应税劳务名称",
  83. )
  84. easy_hwmc: Mapped[str | None] = mapped_column(
  85. String(255),
  86. nullable=True,
  87. comment="货物名称",
  88. )
  89. ggxh: Mapped[str | None] = mapped_column(
  90. String(128),
  91. nullable=True,
  92. comment="规格型号",
  93. )
  94. dw: Mapped[str | None] = mapped_column(
  95. String(16),
  96. nullable=True,
  97. comment="计量单位名称",
  98. )
  99. dw_symbol: Mapped[str | None] = mapped_column(
  100. String(16),
  101. nullable=True,
  102. comment="计量单位符号",
  103. )
  104. # =======================
  105. # 金额 / 数量
  106. # =======================
  107. xssl: Mapped[Decimal] = mapped_column(
  108. Numeric(24, 6),
  109. nullable=False,
  110. default=Decimal("0.000000"),
  111. comment="数量",
  112. )
  113. dj: Mapped[Decimal] = mapped_column(
  114. Numeric(24, 8),
  115. nullable=False,
  116. default=Decimal("0.00000000"),
  117. comment="单价",
  118. )
  119. hjje: Mapped[Decimal] = mapped_column(
  120. Numeric(10, 2),
  121. nullable=False,
  122. default=Decimal("0.00"),
  123. comment="金额",
  124. )
  125. sl: Mapped[str | None] = mapped_column(
  126. String(6),
  127. nullable=True,
  128. comment="税率",
  129. )
  130. hjse: Mapped[Decimal] = mapped_column(
  131. Numeric(10, 2),
  132. nullable=False,
  133. default=Decimal("0.00"),
  134. comment="税额",
  135. )
  136. jshj: Mapped[Decimal] = mapped_column(
  137. Numeric(10, 2),
  138. nullable=False,
  139. default=Decimal("0.00"),
  140. comment="价税合计",
  141. )
  142. # =======================
  143. # 发票状态 / 风控相关
  144. # =======================
  145. fplydm: Mapped[str] = mapped_column(
  146. String(128),
  147. nullable=False,
  148. comment="发票来源",
  149. )
  150. fppzdm: Mapped[str] = mapped_column(
  151. String(128),
  152. nullable=False,
  153. comment="发票票种",
  154. )
  155. fpztdm: Mapped[str] = mapped_column(
  156. String(128),
  157. nullable=False,
  158. comment="发票状态",
  159. )
  160. sflzfp: Mapped[str] = mapped_column(
  161. String(128),
  162. nullable=False,
  163. comment="发票风险等级",
  164. )
  165. kpr: Mapped[str] = mapped_column(
  166. String(64),
  167. nullable=False,
  168. comment="开票人",
  169. )
  170. # =======================
  171. # 时间字段
  172. # =======================
  173. created_at: Mapped[datetime] = mapped_column(
  174. DateTime,
  175. nullable=False,
  176. default=datetime.utcnow,
  177. comment="创建时间",
  178. )
  179. # =======================
  180. # 索引定义
  181. # =======================
  182. __table_args__ = (
  183. Index(
  184. "uni_hm_dm_taxid",
  185. "zzfphm",
  186. "zzfpdm",
  187. "tax_id",
  188. ),
  189. )
  190. def __repr__(self) -> str:
  191. return (
  192. f"<InvoicePurchaseDetail "
  193. f"id={self.id} "
  194. f"tax_id={self.tax_id} "
  195. f"zzfphm={self.zzfphm} "
  196. f"jshj={self.jshj}>"
  197. )