feat: pallets and boxes for deals

This commit is contained in:
2024-12-09 16:45:10 +04:00
parent d56e292276
commit 863dd226c3
14 changed files with 631 additions and 44 deletions

58
models/shipping.py Normal file
View 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')