feat: pallets and boxes for deals
This commit is contained in:
@@ -7,6 +7,7 @@ from sqlalchemy.orm import relationship, backref, Mapped, mapped_column
|
||||
|
||||
from models.base import BaseModel
|
||||
from .marketplace import BaseMarketplace
|
||||
from .shipping import Pallet, Box
|
||||
from .shipping_warehouse import ShippingWarehouse
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -104,6 +105,9 @@ class Deal(BaseModel):
|
||||
manager_id: Mapped[int] = mapped_column(ForeignKey('users.id'), nullable=True)
|
||||
manager: Mapped[Optional["User"]] = relationship(back_populates='managed_deals', lazy='joined')
|
||||
|
||||
pallets: Mapped[list[Pallet]] = relationship(back_populates='deal', lazy='selectin')
|
||||
boxes: Mapped[list[Box]] = relationship(back_populates='deal', lazy='selectin')
|
||||
|
||||
|
||||
class DealStatusHistory(BaseModel):
|
||||
__tablename__ = 'deals_status_history'
|
||||
|
||||
58
models/shipping.py
Normal file
58
models/shipping.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Deal, Product
|
||||
|
||||
|
||||
class Pallet(BaseModel):
|
||||
__tablename__ = 'pallets'
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
|
||||
deal_id: Mapped[int] = mapped_column(ForeignKey('deals.id'))
|
||||
deal: Mapped['Deal'] = relationship(back_populates='pallets')
|
||||
|
||||
boxes: Mapped[list['Box']] = relationship(
|
||||
back_populates='pallet',
|
||||
uselist=True,
|
||||
lazy='joined',
|
||||
cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
shipping_products: Mapped[list['ShippingProduct']] = relationship(
|
||||
back_populates='pallet',
|
||||
uselist=True,
|
||||
lazy='joined',
|
||||
cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
|
||||
class ShippingProduct(BaseModel):
|
||||
__tablename__ = 'shipping_products'
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
quantity: Mapped[int] = mapped_column()
|
||||
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey('products.id'))
|
||||
product: Mapped['Product'] = relationship(lazy='joined')
|
||||
|
||||
pallet_id: Mapped[int] = mapped_column(ForeignKey('pallets.id'))
|
||||
pallet: Mapped['Pallet'] = relationship(lazy='joined')
|
||||
|
||||
|
||||
class Box(BaseModel):
|
||||
__tablename__ = 'boxes'
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
|
||||
quantity: Mapped[int] = mapped_column()
|
||||
|
||||
product_id: Mapped[int] = mapped_column(ForeignKey('products.id'))
|
||||
product: Mapped['Product'] = relationship(lazy='joined')
|
||||
|
||||
pallet_id: Mapped[Optional[int]] = mapped_column(ForeignKey('pallets.id'))
|
||||
pallet: Mapped[Pallet] = relationship(back_populates='boxes')
|
||||
|
||||
deal_id: Mapped[Optional[int]] = mapped_column(ForeignKey('deals.id'))
|
||||
deal: Mapped['Deal'] = relationship(back_populates='boxes')
|
||||
Reference in New Issue
Block a user