""" 成本费用凭证模型 """ from datetime import date from typing import Optional, TYPE_CHECKING from sqlalchemy import ( Boolean, Column, Date, Integer, 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 Expense(BaseModel): """ 成本费用凭证表 """ __tablename__ = "expense" expense_id: Mapped[str] = mapped_column( String(50), unique=True, nullable=False, comment="费用ID" ) voucher_no: Mapped[str] = mapped_column( String(100), nullable=False, comment="凭证号" ) expense_type: Mapped[str] = mapped_column( String(50), nullable=False, comment="费用类型:streamer_commission-主播佣金,platform_fee-平台费用,advertising_fee-广告费,other-其他", ) expense_category: Mapped[str] = mapped_column( String(50), nullable=False, comment="费用类别:sales_expense-销售费用,management_expense-管理费用,financial_expense-财务费用", ) payer_name: Mapped[str] = mapped_column( String(100), nullable=False, comment="付款方名称" ) payer_account_no: Mapped[str] = mapped_column( String(50), nullable=False, comment="付款方账号" ) payee_name: Mapped[str] = mapped_column( String(100), nullable=False, comment="收款方名称" ) payee_account_no: Mapped[str] = mapped_column( String(50), nullable=False, comment="收款方账号" ) payee_bank_name: Mapped[Optional[str]] = mapped_column( String(100), nullable=True, comment="收款方开户行" ) expense_date: Mapped[date] = mapped_column( Date, nullable=False, comment="费用发生日期" ) expense_amount: Mapped[float] = mapped_column( nullable=False, comment="费用金额" ) tax_amount: Mapped[float] = mapped_column( default=0, comment="税额" ) tax_rate: Mapped[float] = mapped_column( default=0, comment="税率" ) payment_method: Mapped[str] = mapped_column( String(50), nullable=False, comment="支付方式:bank_transfer-银行转账,alipay-支付宝,wechat-微信,cash-现金", ) payment_status: Mapped[str] = mapped_column( String(20), nullable=False, comment="支付状态:pending-待支付,processing-处理中,paid-已支付,failed-支付失败", ) accounting_status: Mapped[str] = mapped_column( String(20), nullable=False, comment="入账状态:unposted-未入账,posted-已入账,reversed-已冲销", ) fiscal_year: Mapped[int] = mapped_column( nullable=False, comment="会计年度" ) fiscal_period: Mapped[int] = mapped_column( nullable=False, comment="会计期间" ) is_large_amount: Mapped[bool] = mapped_column( default=False, comment="是否大额费用(>5万)" ) is_cross_border: Mapped[bool] = mapped_column( default=False, comment="是否跨境支付" ) expense_description: Mapped[Optional[str]] = mapped_column( Text, nullable=True, comment="费用说明" ) related_contract_id: Mapped[Optional[str]] = mapped_column( String(50), nullable=True, comment="关联协议ID" )