feat: projects and boards
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
from sqlalchemy.orm import configure_mappers
|
||||
|
||||
from .auth import *
|
||||
from .project import *
|
||||
from .board import *
|
||||
from .status import *
|
||||
from .deal import *
|
||||
from .client import *
|
||||
from .service import *
|
||||
@@ -15,5 +18,6 @@ from .marketplace_products import *
|
||||
from .deal_group import *
|
||||
from .transaction import *
|
||||
from .residues import *
|
||||
from .shipping import *
|
||||
|
||||
configure_mappers()
|
||||
|
||||
31
models/board.py
Normal file
31
models/board.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Project, DealStatus, Deal
|
||||
|
||||
|
||||
class Board(BaseModel):
|
||||
__tablename__ = "boards"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(nullable=False)
|
||||
is_deleted: Mapped[bool] = mapped_column(default=False)
|
||||
ordinal_number: Mapped[int] = mapped_column(nullable=False)
|
||||
|
||||
project_id: Mapped[int] = mapped_column(ForeignKey('projects.id'), nullable=False)
|
||||
project: Mapped["Project"] = relationship(
|
||||
"Project",
|
||||
back_populates="boards",
|
||||
lazy="selectin",
|
||||
)
|
||||
|
||||
deal_statuses: Mapped[list["DealStatus"]] = relationship("DealStatus", back_populates="board", lazy="selectin", cascade="all,delete")
|
||||
|
||||
deals: Mapped[list["Deal"]] = relationship("Deal", uselist=True, back_populates="board", lazy="selectin")
|
||||
@@ -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)
|
||||
|
||||
24
models/project.py
Normal file
24
models/project.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from datetime import datetime
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from board import Board
|
||||
|
||||
|
||||
class Project(BaseModel):
|
||||
__tablename__ = "projects"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
created_at: Mapped[datetime] = mapped_column(nullable=False)
|
||||
is_deleted: Mapped[bool] = mapped_column(default=False)
|
||||
|
||||
boards: Mapped[list["Board"]] = relationship(
|
||||
"Board",
|
||||
back_populates="project",
|
||||
lazy="noload",
|
||||
)
|
||||
61
models/status.py
Normal file
61
models/status.py
Normal file
@@ -0,0 +1,61 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import ForeignKey, Column, Integer, DateTime, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Board
|
||||
|
||||
|
||||
class DealStatus(BaseModel):
|
||||
__tablename__ = "deal_statuses"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
ordinal_number: Mapped[int] = mapped_column(nullable=False)
|
||||
is_finishing: Mapped[bool] = mapped_column(default=False, nullable=False)
|
||||
is_deleted: Mapped[bool] = mapped_column(default=False, nullable=False)
|
||||
|
||||
board_id: Mapped[int] = mapped_column(ForeignKey('boards.id'), nullable=False)
|
||||
board: Mapped["Board"] = relationship("Board", back_populates="deal_statuses")
|
||||
|
||||
|
||||
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_id: Mapped[int] = mapped_column(
|
||||
ForeignKey('deal_statuses.id'),
|
||||
nullable=False,
|
||||
comment='Предыдущий статус',
|
||||
)
|
||||
from_status: Mapped[DealStatus] = relationship(
|
||||
'DealStatus',
|
||||
foreign_keys=[from_status_id],
|
||||
lazy='joined',
|
||||
)
|
||||
|
||||
to_status_id: Mapped[int] = mapped_column(
|
||||
ForeignKey('deal_statuses.id'),
|
||||
nullable=False,
|
||||
comment='Новый статус',
|
||||
)
|
||||
to_status: Mapped[DealStatus] = relationship(
|
||||
'DealStatus',
|
||||
foreign_keys=[to_status_id],
|
||||
lazy='joined',
|
||||
)
|
||||
|
||||
next_status_deadline = Column(DateTime,
|
||||
comment='Дедлайн до которого сделку нужно перевести на следующий этап')
|
||||
comment = Column(String, nullable=False, comment='Коментарий', server_default='')
|
||||
Reference in New Issue
Block a user