feat: projects and boards
This commit is contained in:
		@@ -7,6 +7,8 @@ from sqlalchemy.orm import relationship, backref, Mapped, mapped_column
 | 
			
		||||
 | 
			
		||||
from models.base import BaseModel
 | 
			
		||||
from .marketplace import BaseMarketplace
 | 
			
		||||
from .board import Board
 | 
			
		||||
from .status import DealStatus
 | 
			
		||||
from .shipping import Pallet, Box
 | 
			
		||||
from .shipping_warehouse import ShippingWarehouse
 | 
			
		||||
 | 
			
		||||
@@ -19,18 +21,8 @@ if TYPE_CHECKING:
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
# @unique
 | 
			
		||||
# class DealStatus(IntEnum):
 | 
			
		||||
#     CREATED = 0
 | 
			
		||||
#     AWAITING_ACCEPTANCE = 1
 | 
			
		||||
#     PACKAGING = 2
 | 
			
		||||
#     AWAITING_SHIPMENT = 3
 | 
			
		||||
#     AWAITING_PAYMENT = 4
 | 
			
		||||
#     COMPLETED = 5
 | 
			
		||||
#     CANCELLED = 6
 | 
			
		||||
 | 
			
		||||
@unique
 | 
			
		||||
class DealStatus(IntEnum):
 | 
			
		||||
class DealStatusEnum(IntEnum):
 | 
			
		||||
    CREATED = 0
 | 
			
		||||
    AWAITING_ACCEPTANCE = 1
 | 
			
		||||
    READY_FOR_WORK = 2
 | 
			
		||||
@@ -53,7 +45,6 @@ class Deal(BaseModel):
 | 
			
		||||
    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
			
		||||
    name = Column(String, nullable=False, comment='Название сделки')
 | 
			
		||||
    created_at = Column(DateTime, nullable=False, comment='Дата создания')
 | 
			
		||||
    current_status = Column(Integer, nullable=False, comment='Текущий статус')
 | 
			
		||||
 | 
			
		||||
    client_id = Column(Integer, ForeignKey('clients.id', ondelete='CASCADE'), nullable=False, comment='ID клиента')
 | 
			
		||||
    client = relationship('Client', backref=backref('deals', cascade="all, delete-orphan"))
 | 
			
		||||
@@ -65,6 +56,14 @@ class Deal(BaseModel):
 | 
			
		||||
    is_locked: Mapped[bool] = mapped_column(default=False, server_default='0')
 | 
			
		||||
    is_accounted: Mapped[bool] = mapped_column(default=True, server_default='1')
 | 
			
		||||
 | 
			
		||||
    current_status_id: Mapped[int] = mapped_column(
 | 
			
		||||
        ForeignKey("deal_statuses.id"),
 | 
			
		||||
        nullable=False,
 | 
			
		||||
        comment='Текущий статус',
 | 
			
		||||
    )
 | 
			
		||||
    status: Mapped["DealStatus"] = relationship(lazy="selectin")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    shipping_warehouse_id: Mapped[int] = mapped_column(ForeignKey('shipping_warehouses.id'), nullable=True)
 | 
			
		||||
    shipping_warehouse: Mapped["ShippingWarehouse"] = relationship()
 | 
			
		||||
 | 
			
		||||
@@ -88,6 +87,12 @@ class Deal(BaseModel):
 | 
			
		||||
        order_by="desc(DealProduct.product_id)"
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    board_id: Mapped[int] = mapped_column(ForeignKey('boards.id'), nullable=True, server_default='1')
 | 
			
		||||
    board: Mapped[Board] = relationship(
 | 
			
		||||
        "Board",
 | 
			
		||||
        back_populates="deals",
 | 
			
		||||
    )
 | 
			
		||||
 | 
			
		||||
    # TODO remake with sequence
 | 
			
		||||
    lexorank = Column(String, nullable=False, comment='Lexorank', index=True)
 | 
			
		||||
 | 
			
		||||
@@ -112,25 +117,6 @@ class Deal(BaseModel):
 | 
			
		||||
    employees: Mapped[list['DealEmployees']] = relationship(back_populates='deal', lazy='selectin')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DealStatusHistory(BaseModel):
 | 
			
		||||
    __tablename__ = 'deals_status_history'
 | 
			
		||||
    id = Column(Integer, autoincrement=True, primary_key=True, index=True)
 | 
			
		||||
 | 
			
		||||
    deal_id = Column(Integer, ForeignKey('deals.id'), nullable=False, comment='ID сделки')
 | 
			
		||||
    deal = relationship('Deal', back_populates='status_history')
 | 
			
		||||
 | 
			
		||||
    user_id = Column(Integer, ForeignKey('users.id'), nullable=False)
 | 
			
		||||
    user = relationship('User')
 | 
			
		||||
 | 
			
		||||
    changed_at = Column(DateTime, nullable=False, comment='Дата и время когда произошла смена статуса')
 | 
			
		||||
    from_status = Column(Integer, nullable=False, comment='Предыдущий статус')
 | 
			
		||||
    to_status = Column(Integer, nullable=False, comment='Новый статус')
 | 
			
		||||
 | 
			
		||||
    next_status_deadline = Column(DateTime,
 | 
			
		||||
                                  comment='Дедлайн до которого сделку нужно перевести на следующий этап')
 | 
			
		||||
    comment = Column(String, nullable=False, comment='Коментарий', server_default='')
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class DealEmployees(BaseModel):
 | 
			
		||||
    __tablename__ = 'deal_employees'
 | 
			
		||||
    user_id: Mapped[int] = mapped_column(ForeignKey('users.id'), primary_key=True)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user