feat(agent): 立账凭证检核
(cherry picked from commit f9e2fb5efc1ec7bf4f6e52e08dd3591b4e77edd9)
This commit is contained in:
1 parent
9bcbf9d211
commit
f615e56bb9
70 files changed
+4968
-108
No files matched your search
@@ -2,7 +2,7 @@
|
||||
backend/app/models/__init__.py
|
||||
|
||||
用途:按业务域拆分的 ORM 模型包入口;聚合导出以保持 `from app.models import User` 兼容。
|
||||
依赖:models/* 子模块、app.extensions.db(经 base.Base)。
|
||||
依赖:models/* 子模块(含 voucher_check)、app.extensions.db(经 base.Base)。
|
||||
逻辑:Alembic / Flask-Migrate 通过本模块 import 注册全部表元数据;业务代码继续从此处导入模型类。
|
||||
"""
|
||||
|
||||
@@ -32,6 +32,7 @@ from app.models.shipping import (
|
||||
)
|
||||
from app.models.training import TrainingRecord
|
||||
from app.models.user import LoginAudit, User, UserDefaultAgent, UserFavoriteAgent, UserHomepageConfig
|
||||
from app.models.voucher_check import VoucherCheckInvoiceState, VoucherCheckRunItem
|
||||
from app.models.wecom import WecomCallbackAudit, WecomNotifyAudit
|
||||
|
||||
__all__ = [
|
||||
@@ -86,4 +87,6 @@ __all__ = [
|
||||
'MaintenanceDevice',
|
||||
'MaintenanceRecord',
|
||||
'MaintenanceAuditLog',
|
||||
'VoucherCheckInvoiceState',
|
||||
'VoucherCheckRunItem',
|
||||
]
|
||||
@@ -0,0 +1,114 @@
|
||||
"""
|
||||
backend/app/models/voucher_check.py
|
||||
|
||||
用途:立账凭证检核单票最新状态与批次明细 ORM。
|
||||
依赖:models.base.Base、schedule_runs。
|
||||
逻辑:runner/persistence 写入;query_service 与工作台 API 读取;增量跳过依赖 invoice_states。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import (
|
||||
BigInteger,
|
||||
Boolean,
|
||||
Date,
|
||||
DateTime,
|
||||
ForeignKey,
|
||||
Index,
|
||||
JSON,
|
||||
String,
|
||||
Text,
|
||||
UniqueConstraint,
|
||||
)
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
|
||||
from app.models.base import Base
|
||||
|
||||
|
||||
class VoucherCheckInvoiceState(Base):
|
||||
"""账套+月份+发票号的最新材料齐全状态(增量跳过真相源)。"""
|
||||
|
||||
__tablename__ = "voucher_check_invoice_states"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"scope_code",
|
||||
"period_month",
|
||||
"invoice_no",
|
||||
name="uq_voucher_check_invoice_states_scope_period_invoice",
|
||||
),
|
||||
Index("ix_voucher_check_invoice_states_period_status", "period_month", "status"),
|
||||
Index("ix_voucher_check_invoice_states_invoice_no", "invoice_no"),
|
||||
Index("ix_voucher_check_invoice_states_notified_on", "last_missing_notified_on"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
scope_code: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
period_month: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
invoice_no: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
invoice_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
status: Mapped[str] = mapped_column(String(24), nullable=False)
|
||||
folder_path: Mapped[Optional[str]] = mapped_column(String(1024), nullable=True)
|
||||
folder_exists: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
material_fingerprint: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
matched_files_json: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
|
||||
missing_materials_json: Mapped[Optional[list]] = mapped_column(JSON, nullable=True)
|
||||
last_actual_run_id: Mapped[Optional[int]] = mapped_column(
|
||||
BigInteger,
|
||||
ForeignKey("schedule_runs.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
)
|
||||
last_checked_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
last_seen_erp_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
last_missing_notified_on: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
updated_at: Mapped[datetime] = mapped_column(
|
||||
DateTime,
|
||||
default=datetime.utcnow,
|
||||
onupdate=datetime.utcnow,
|
||||
nullable=False,
|
||||
)
|
||||
|
||||
|
||||
class VoucherCheckRunItem(Base):
|
||||
"""单次 ScheduleRun 的发票检核快照(含跳过项,供审计与 Excel)。"""
|
||||
|
||||
__tablename__ = "voucher_check_run_items"
|
||||
__table_args__ = (
|
||||
UniqueConstraint(
|
||||
"schedule_run_id",
|
||||
"invoice_no",
|
||||
name="uq_voucher_check_run_items_run_invoice",
|
||||
),
|
||||
Index("ix_voucher_check_run_items_run_result", "schedule_run_id", "result"),
|
||||
Index("ix_voucher_check_run_items_period_result", "period_month", "result"),
|
||||
)
|
||||
|
||||
id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
|
||||
schedule_run_id: Mapped[int] = mapped_column(
|
||||
BigInteger,
|
||||
ForeignKey("schedule_runs.id", ondelete="CASCADE"),
|
||||
nullable=False,
|
||||
index=True,
|
||||
)
|
||||
invoice_state_id: Mapped[Optional[int]] = mapped_column(
|
||||
BigInteger,
|
||||
ForeignKey("voucher_check_invoice_states.id", ondelete="SET NULL"),
|
||||
nullable=True,
|
||||
)
|
||||
scope_code: Mapped[str] = mapped_column(String(32), nullable=False)
|
||||
period_month: Mapped[date] = mapped_column(Date, nullable=False)
|
||||
invoice_no: Mapped[str] = mapped_column(String(128), nullable=False)
|
||||
invoice_date: Mapped[Optional[date]] = mapped_column(Date, nullable=True)
|
||||
result: Mapped[str] = mapped_column(String(24), nullable=False)
|
||||
folder_path: Mapped[Optional[str]] = mapped_column(String(1024), nullable=True)
|
||||
folder_exists: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
material_fingerprint: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
matched_files_json: Mapped[Optional[dict]] = mapped_column(JSON, nullable=True)
|
||||
missing_materials_json: Mapped[Optional[list]] = mapped_column(JSON, nullable=True)
|
||||
error_code: Mapped[Optional[str]] = mapped_column(String(64), nullable=True)
|
||||
error_message: Mapped[Optional[str]] = mapped_column(Text, nullable=True)
|
||||
checked_at: Mapped[Optional[datetime]] = mapped_column(DateTime, nullable=True)
|
||||
created_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, nullable=False)
|
||||
Reference in new issue
Block a user