Files
2026-09-30 16:42:02 +03:00

47 lines
1.8 KiB
Python

from sqlalchemy import Column, Integer, String, Date, DateTime, Text, Numeric
from sqlalchemy.sql import func
from app.database.database import Base
from datetime import datetime
from typing import Optional
from sqlalchemy.orm import relationship
class Project(Base):
__tablename__ = "projects"
id = Column(Integer, primary_key=True, index=True)
name = Column(String, index=True, nullable=False)
contract_number = Column(String)
contract_date = Column(Date)
customer = Column(String) # domain: customer_name
currency = Column(String, default="RUB")
start_date = Column(Date)
end_date = Column(Date)
status = Column(String, default="active")
created_at = Column(DateTime, default=func.now())
updated_at = Column(DateTime, default=func.now(), onupdate=func.now())
# Official document requisites (DOC-B10)
investor_name = Column(String)
customer_name = Column(String) # preferred domain name for customer
contractor_name = Column(String)
construction_name = Column(String)
object_name = Column(String)
contract_amount = Column(Numeric(18, 2))
contractor_signer_name = Column(String)
contractor_signer_position = Column(String)
customer_signer_name = Column(String)
customer_signer_position = Column(String)
# Relationships
boq_documents = relationship("BoqDocument", back_populates="project")
systems = relationship("System", back_populates="project")
agreements = relationship("Agreement", back_populates="project", cascade="all, delete-orphan")
@property
def effective_customer_name(self) -> str:
"""Return customer_name if set, else fall back to legacy customer field."""
return self.customer_name or self.customer or ""
def __repr__(self):
return f"<Project(id={self.id}, name='{self.name}')>"