46 lines
2.1 KiB
Python
46 lines
2.1 KiB
Python
|
|
"""inventory 财务域模型:收付款交易与订单分摊。"""
|
||
|
|
from sqlalchemy import Column, Integer, String, Text, DateTime, Numeric, ForeignKey
|
||
|
|
from sqlalchemy.sql import func
|
||
|
|
from sqlalchemy.orm import relationship
|
||
|
|
|
||
|
|
from shared.models.base import Base
|
||
|
|
|
||
|
|
|
||
|
|
class FinanceTransaction(Base):
|
||
|
|
__tablename__ = "finance_transactions"
|
||
|
|
|
||
|
|
id = Column(Integer, primary_key=True, index=True)
|
||
|
|
txn_no = Column(String(50), unique=True, index=True, nullable=False)
|
||
|
|
txn_type = Column(String(20), nullable=False, index=True)
|
||
|
|
partner_type = Column(String(20), nullable=False, index=True)
|
||
|
|
partner_id = Column(Integer, nullable=False, index=True)
|
||
|
|
amount = Column(Numeric(12, 2), nullable=False)
|
||
|
|
txn_date = Column(DateTime, default=func.now(), index=True)
|
||
|
|
method = Column(String(30), default="bank")
|
||
|
|
account_name = Column(String(100), nullable=True)
|
||
|
|
status = Column(String(20), default="confirmed", index=True)
|
||
|
|
remark = Column(Text, nullable=True)
|
||
|
|
operator_id = Column(Integer, ForeignKey("users.id"), nullable=True)
|
||
|
|
created_at = Column(DateTime, default=func.now(), index=True)
|
||
|
|
|
||
|
|
allocations = relationship("FinanceAllocation", back_populates="transaction", cascade="all, delete-orphan")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<FinanceTransaction(txn_no='{self.txn_no}', txn_type='{self.txn_type}', amount={self.amount})>"
|
||
|
|
|
||
|
|
|
||
|
|
class FinanceAllocation(Base):
|
||
|
|
__tablename__ = "finance_allocations"
|
||
|
|
|
||
|
|
id = Column(Integer, primary_key=True, index=True)
|
||
|
|
transaction_id = Column(Integer, ForeignKey("finance_transactions.id"), nullable=False, index=True)
|
||
|
|
order_type = Column(String(20), nullable=False, index=True)
|
||
|
|
order_id = Column(Integer, nullable=False, index=True)
|
||
|
|
allocated_amount = Column(Numeric(12, 2), nullable=False)
|
||
|
|
created_at = Column(DateTime, default=func.now(), index=True)
|
||
|
|
|
||
|
|
transaction = relationship("FinanceTransaction", back_populates="allocations")
|
||
|
|
|
||
|
|
def __repr__(self):
|
||
|
|
return f"<FinanceAllocation(transaction_id={self.transaction_id}, order_type='{self.order_type}', amount={self.allocated_amount})>"
|