deep-risk/backend/app/models/invoice.py
2025-12-14 20:08:27 +08:00

99 lines
3.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
发票数据模型
"""
from datetime import datetime
from typing import Optional, TYPE_CHECKING
from sqlalchemy import (
Boolean,
Column,
Date,
DateTime,
String,
Text,
Float,
)
from sqlalchemy.orm import Mapped, mapped_column
from app.models.base import BaseModel
if TYPE_CHECKING:
from .streamer import StreamerInfo, McnAgency
class Invoice(BaseModel):
"""
发票数据表
"""
__tablename__ = "invoice"
invoice_id: Mapped[str] = mapped_column(
String(50), unique=True, nullable=False, comment="发票ID"
)
invoice_code: Mapped[str] = mapped_column(
String(20), nullable=False, comment="发票代码"
)
invoice_no: Mapped[str] = mapped_column(
String(20), nullable=False, comment="发票号码"
)
invoice_type: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="发票类型vat_special-增值税专用发票vat_general-增值税普通发票electronic-电子发票",
)
direction: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="发票方向issued-已开具received-已收到",
)
invoice_date: Mapped[Date] = mapped_column(
Date, nullable=False, comment="开票日期"
)
purchaser_name: Mapped[str] = mapped_column(
String(200), nullable=False, comment="购买方名称"
)
purchaser_tax_no: Mapped[str] = mapped_column(
String(18), nullable=False, comment="购买方税号"
)
seller_name: Mapped[str] = mapped_column(
String(200), nullable=False, comment="销售方名称"
)
seller_tax_no: Mapped[str] = mapped_column(
String(18), nullable=False, comment="销售方税号"
)
total_amount: Mapped[float] = mapped_column(
nullable=False, comment="金额合计"
)
total_tax: Mapped[float] = mapped_column(
nullable=False, comment="税额合计"
)
total_amount_with_tax: Mapped[float] = mapped_column(
nullable=False, comment="价税合计"
)
amount_in_words: Mapped[str] = mapped_column(
String(200), nullable=False, comment="大写金额"
)
invoice_status: Mapped[str] = mapped_column(
String(20),
nullable=False,
comment="发票状态normal-正常cancelled-已作废red-红字returned-退回",
)
is_verified: Mapped[bool] = mapped_column(
default=False, comment="是否已验证"
)
verified_time: Mapped[Optional[datetime]] = mapped_column(
DateTime(timezone=True), nullable=True, comment="验证时间"
)
is_red_invoice: Mapped[bool] = mapped_column(
default=False, comment="是否红字发票"
)
red_reason: Mapped[Optional[str]] = mapped_column(
String(100), nullable=True, comment="红字原因"
)
remark: Mapped[Optional[str]] = mapped_column(
Text, nullable=True, comment="备注"
)
pdf_url: Mapped[Optional[str]] = mapped_column(
String(500), nullable=True, comment="PDF文件地址"
)