Store optional expense occurrence date (DATE, nullable) for each reimburse line item. Co-authored-by: Cursor <cursoragent@cursor.com>
362 lines
22 KiB
Python
362 lines
22 KiB
Python
"""报销(bx)模块数据模型 — 对齐 docs/sql/20260606_bx_tables.sql"""
|
||
from datetime import datetime
|
||
|
||
from sqlalchemy import BigInteger, Column, Date, DateTime, DECIMAL, ForeignKey, Integer, SmallInteger, String
|
||
from sqlalchemy.orm import relationship
|
||
|
||
from app.core.database import Base
|
||
|
||
|
||
class BxExpenseItem(Base):
|
||
__tablename__ = "bx_expense_item"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
parent_id = Column(String(64), nullable=False, default="0", comment="父级项目ID")
|
||
item_name = Column(String(128), nullable=False, comment="项目名称")
|
||
item_code = Column(String(64), nullable=True, comment="项目编码")
|
||
level = Column(SmallInteger, nullable=False, default=1, comment="层级")
|
||
sort_order = Column(Integer, nullable=False, default=0, comment="排序号")
|
||
status = Column(SmallInteger, nullable=False, default=1, comment="状态")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxWorkflowDef(Base):
|
||
__tablename__ = "bx_workflow_def"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
biz_type = Column(String(32), nullable=False, comment="业务类型")
|
||
wf_name = Column(String(128), nullable=False, comment="工作流名称")
|
||
status = Column(SmallInteger, nullable=False, default=1, comment="状态")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
nodes = relationship(
|
||
"BxWorkflowNode",
|
||
back_populates="workflow_def",
|
||
primaryjoin="and_(BxWorkflowDef.id == BxWorkflowNode.wf_id, BxWorkflowNode.del_flag == 0)",
|
||
foreign_keys="BxWorkflowNode.wf_id",
|
||
order_by="BxWorkflowNode.node_order",
|
||
lazy="selectin",
|
||
)
|
||
|
||
|
||
class BxWorkflowNode(Base):
|
||
__tablename__ = "bx_workflow_node"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
wf_id = Column(
|
||
String(64),
|
||
ForeignKey("bx_workflow_def.id"),
|
||
nullable=False,
|
||
comment="工作流定义ID",
|
||
)
|
||
node_name = Column(String(128), nullable=False, comment="节点名称")
|
||
node_order = Column(Integer, nullable=False, default=0, comment="节点顺序")
|
||
approver_id = Column(String(64), nullable=True, comment="审批人用户ID")
|
||
approver_name = Column(String(64), nullable=True, comment="审批人姓名")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
workflow_def = relationship(
|
||
"BxWorkflowDef",
|
||
back_populates="nodes",
|
||
foreign_keys=[wf_id],
|
||
)
|
||
|
||
|
||
class BxAdvanceApply(Base):
|
||
__tablename__ = "bx_advance_apply"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
apply_code = Column(String(32), nullable=False, comment="申请单号")
|
||
applicant_id = Column(String(64), nullable=False, comment="申请人用户ID")
|
||
applicant_name = Column(String(64), nullable=False, comment="申请人姓名")
|
||
reason = Column(String(1024), nullable=False, comment="申请原因")
|
||
purpose = Column(String(1024), nullable=True, comment="申请目的")
|
||
expense_item_id = Column(String(64), nullable=True, comment="费用项目ID")
|
||
amount = Column(DECIMAL(14, 2), nullable=False, comment="申请金额")
|
||
status = Column(String(32), nullable=False, default="draft", comment="状态")
|
||
current_node = Column(String(128), nullable=True, comment="当前审批节点")
|
||
wf_id = Column(String(64), nullable=True, comment="工作流定义ID")
|
||
issue_status = Column(String(32), nullable=True, comment="发放状态")
|
||
issue_time = Column(DateTime, nullable=True, comment="发放时间")
|
||
issue_user_id = Column(String(64), nullable=True, comment="发放操作人ID")
|
||
issue_user_name = Column(String(64), nullable=True, comment="发放操作人姓名")
|
||
issue_remark = Column(String(512), nullable=True, comment="发放备注")
|
||
actual_amount = Column(DECIMAL(14, 2), nullable=True, comment="实际发放金额")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxAdvanceApproval(Base):
|
||
__tablename__ = "bx_advance_approval"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
apply_id = Column(String(64), nullable=False, comment="备用金申请单ID")
|
||
node_order = Column(Integer, nullable=False, comment="节点顺序")
|
||
node_name = Column(String(128), nullable=False, comment="节点名称")
|
||
approver_id = Column(String(64), nullable=False, comment="审批人用户ID")
|
||
approver_name = Column(String(64), nullable=False, comment="审批人姓名")
|
||
approval_status = Column(String(32), nullable=False, comment="审批结果")
|
||
approval_opinion = Column(String(1024), nullable=True, comment="审批意见")
|
||
approval_time = Column(DateTime, nullable=False, comment="审批时间")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(DateTime, nullable=True, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxReimburseApply(Base):
|
||
__tablename__ = "bx_reimburse_apply"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
apply_code = Column(String(32), nullable=False, comment="报销单号")
|
||
title = Column(String(256), nullable=False, comment="报销标题")
|
||
reimburse_date = Column(Date, nullable=False, comment="报销日期")
|
||
title_seq = Column(Integer, nullable=True, comment="标题序号(同租户同报销日期下自增)")
|
||
applicant_id = Column(String(64), nullable=False, comment="申请人用户ID")
|
||
applicant_name = Column(String(64), nullable=False, comment="申请人姓名")
|
||
expense_id = Column(String(64), nullable=False, comment="费用项目ID")
|
||
expense_name = Column(String(128), nullable=False, comment="费用项目名称")
|
||
amount = Column(DECIMAL(14, 2), nullable=False, comment="报销金额")
|
||
invoice_count = Column(Integer, nullable=False, default=0, comment="发票数量")
|
||
attach_count = Column(Integer, nullable=False, default=0, comment="附件数量")
|
||
status = Column(String(32), nullable=False, default="draft", comment="状态")
|
||
current_node = Column(String(128), nullable=True, comment="当前审批节点")
|
||
wf_id = Column(String(64), nullable=True, comment="工作流定义ID")
|
||
pay_status = Column(String(32), nullable=True, comment="支付状态")
|
||
pay_time = Column(DateTime, nullable=True, comment="支付时间")
|
||
pay_user_id = Column(String(64), nullable=True, comment="支付操作人ID")
|
||
pay_user_name = Column(String(64), nullable=True, comment="支付操作人姓名")
|
||
actual_amount = Column(DECIMAL(14, 2), nullable=True, comment="实际发放金额")
|
||
offset_advance_id = Column(String(64), nullable=True, comment="冲抵备用金单ID")
|
||
offset_amount = Column(DECIMAL(14, 2), nullable=True, comment="冲抵金额")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注说明")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxReimburseDetail(Base):
|
||
__tablename__ = "bx_reimburse_detail"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
reimburse_id = Column(String(64), nullable=False, comment="报销单ID")
|
||
expense_id = Column(String(64), nullable=False, comment="费用项目ID")
|
||
expense_name = Column(String(128), nullable=False, comment="费用项目名称")
|
||
amount = Column(DECIMAL(14, 2), nullable=False, comment="报销金额")
|
||
occur_date = Column(Date, nullable=True, comment="费用发生日期")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxReimburseApproval(Base):
|
||
__tablename__ = "bx_reimburse_approval"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
apply_id = Column(String(64), nullable=False, comment="报销申请单ID")
|
||
node_order = Column(Integer, nullable=False, comment="节点顺序")
|
||
node_name = Column(String(128), nullable=False, comment="节点名称")
|
||
approver_id = Column(String(64), nullable=False, comment="审批人用户ID")
|
||
approver_name = Column(String(64), nullable=False, comment="审批人姓名")
|
||
approval_status = Column(String(32), nullable=False, comment="审批结果")
|
||
approval_opinion = Column(String(1024), nullable=True, comment="审批意见")
|
||
approval_time = Column(DateTime, nullable=False, comment="审批时间")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(DateTime, nullable=True, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxReimburseOffset(Base):
|
||
__tablename__ = "bx_reimburse_offset"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
reimburse_id = Column(String(64), nullable=False, comment="报销申请单ID")
|
||
advance_id = Column(String(64), nullable=False, comment="备用金申请单ID")
|
||
offset_amount = Column(DECIMAL(14, 2), nullable=False, comment="冲抵金额")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(DateTime, nullable=True, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxAttachment(Base):
|
||
__tablename__ = "bx_attachment"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
biz_type = Column(String(32), nullable=False, comment="业务类型")
|
||
biz_id = Column(String(64), nullable=False, comment="业务单据ID")
|
||
file_name = Column(String(256), nullable=False, comment="文件名")
|
||
file_path = Column(String(512), nullable=False, comment="文件存储路径")
|
||
file_type = Column(String(128), nullable=True, comment="文件MIME类型")
|
||
file_size = Column(BigInteger, nullable=True, comment="文件大小")
|
||
attach_type = Column(String(32), nullable=True, default="attachment", comment="附件类型")
|
||
sort_order = Column(Integer, nullable=False, default=0, comment="排序号")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(DateTime, nullable=True, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxInvoice(Base):
|
||
__tablename__ = "bx_invoice"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键UUID")
|
||
owner_user_id = Column(String(64), nullable=False, comment="所属员工ID")
|
||
owner_user_name = Column(String(64), nullable=False, comment="所属员工姓名")
|
||
amount = Column(DECIMAL(14, 2), nullable=False, comment="入账金额")
|
||
upload_by = Column(String(64), nullable=True, comment="上传操作人ID")
|
||
upload_by_name = Column(String(64), nullable=True, comment="上传操作人姓名")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxInvoiceLedger(Base):
|
||
__tablename__ = "bx_invoice_ledger"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
owner_user_id = Column(String(64), nullable=False, comment="所属员工ID")
|
||
entry_type = Column(
|
||
String(32),
|
||
nullable=False,
|
||
comment="credit_upload|debit_delete|debit_reimburse|credit_release",
|
||
)
|
||
amount = Column(DECIMAL(14, 2), nullable=False, comment="正数,方向由 entry_type 决定")
|
||
invoice_id = Column(String(64), nullable=True, comment="发票档案ID")
|
||
reimburse_id = Column(String(64), nullable=True, comment="报销单ID")
|
||
ref_ledger_id = Column(String(64), nullable=True, comment="退回指向原占用流水")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(DateTime, nullable=True, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxReimburseInvoice(Base):
|
||
__tablename__ = "bx_reimburse_invoice"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
reimburse_id = Column(String(64), nullable=False, comment="报销单ID")
|
||
invoice_id = Column(String(64), nullable=False, comment="发票档案ID")
|
||
attachment_id = Column(String(64), nullable=True, comment="勾选的发票附件ID")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(DateTime, nullable=True, onupdate=datetime.now, comment="更新时间")
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|
||
|
||
|
||
class BxInvoiceWalletSummary(Base):
|
||
__tablename__ = "bx_invoice_wallet_summary"
|
||
|
||
id = Column(String(64), primary_key=True, comment="主键ID(UUID)")
|
||
owner_user_id = Column(String(64), nullable=False, comment="所属员工ID")
|
||
owner_user_name = Column(String(64), nullable=False, default="", comment="所属员工姓名")
|
||
total_amount = Column(DECIMAL(14, 2), nullable=False, default=0, comment="累计入账金额")
|
||
used_amount = Column(DECIMAL(14, 2), nullable=False, default=0, comment="已占用金额")
|
||
balance = Column(DECIMAL(14, 2), nullable=False, default=0, comment="可用余额")
|
||
invoice_count = Column(Integer, nullable=False, default=0, comment="发票数量")
|
||
version = Column(Integer, nullable=False, default=0, comment="乐观锁版本号")
|
||
tenant_no = Column(String(64), nullable=False, default="shanxia2.0", comment="租户编号")
|
||
order_num = Column(Integer, nullable=True, comment="排序号(公共)")
|
||
remark = Column(String(512), nullable=True, comment="备注")
|
||
create_by = Column(String(64), nullable=True, comment="创建人")
|
||
create_dept_id = Column(String(64), nullable=False, default="", comment="创建部门")
|
||
create_time = Column(DateTime, nullable=False, default=datetime.now, comment="创建时间")
|
||
update_by = Column(String(64), nullable=True, comment="更新人")
|
||
update_time = Column(
|
||
DateTime, nullable=False, default=datetime.now, onupdate=datetime.now, comment="更新时间"
|
||
)
|
||
del_flag = Column(SmallInteger, nullable=False, default=0, comment="删除标记")
|