Files
smart-project-pricing/后端服务/app/models/project_cost_item.py
2026-01-31 21:33:06 +08:00

67 lines
1.6 KiB
Python
Raw 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 typing import Optional, TYPE_CHECKING
from decimal import Decimal
from sqlalchemy import BigInteger, String, DECIMAL, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship
from app.models.base import BaseModel
if TYPE_CHECKING:
from app.models.project import Project
class ProjectCostItem(BaseModel):
"""项目成本明细表(耗材/设备)"""
__tablename__ = "project_cost_items"
project_id: Mapped[int] = mapped_column(
BigInteger,
ForeignKey("projects.id", ondelete="CASCADE"),
nullable=False,
index=True,
comment="项目ID"
)
item_type: Mapped[str] = mapped_column(
String(20),
nullable=False,
index=True,
comment="类型material-耗材, equipment-设备"
)
item_id: Mapped[int] = mapped_column(
BigInteger,
nullable=False,
comment="耗材/设备ID"
)
quantity: Mapped[Decimal] = mapped_column(
DECIMAL(10, 4),
nullable=False,
comment="用量"
)
unit_cost: Mapped[Decimal] = mapped_column(
DECIMAL(12, 4),
nullable=False,
comment="单位成本"
)
total_cost: Mapped[Decimal] = mapped_column(
DECIMAL(12, 2),
nullable=False,
comment="总成本 = quantity * unit_cost"
)
remark: Mapped[Optional[str]] = mapped_column(
String(200),
nullable=True,
comment="备注"
)
# 关系
project: Mapped["Project"] = relationship(
"Project",
back_populates="cost_items"
)