feat: residues accounting
This commit is contained in:
62
models/residues.py
Normal file
62
models/residues.py
Normal file
@@ -0,0 +1,62 @@
|
||||
import datetime
|
||||
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 Product, Client
|
||||
|
||||
|
||||
class ResidualPallet(BaseModel):
|
||||
__tablename__ = 'residual_pallets'
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
created_at: Mapped[datetime.datetime] = mapped_column(nullable=False)
|
||||
|
||||
client_id: Mapped[Optional[int]] = mapped_column(ForeignKey('clients.id'))
|
||||
client: Mapped['Client'] = relationship(back_populates='pallets')
|
||||
|
||||
boxes: Mapped[list['ResidualBox']] = relationship(
|
||||
back_populates='pallet',
|
||||
uselist=True,
|
||||
lazy='joined',
|
||||
cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
residual_products: Mapped[list['ResidualProduct']] = relationship(
|
||||
back_populates='pallet',
|
||||
uselist=True,
|
||||
lazy='joined',
|
||||
cascade='all, delete-orphan',
|
||||
)
|
||||
|
||||
|
||||
class ResidualProduct(BaseModel):
|
||||
__tablename__ = 'residual_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[Optional[int]] = mapped_column(ForeignKey('residual_pallets.id'))
|
||||
pallet: Mapped[ResidualPallet] = relationship(lazy='joined', back_populates="residual_products")
|
||||
|
||||
box_id: Mapped[Optional[int]] = mapped_column(ForeignKey('residual_boxes.id'))
|
||||
box: Mapped['ResidualBox'] = relationship(back_populates='residual_products')
|
||||
|
||||
|
||||
class ResidualBox(BaseModel):
|
||||
__tablename__ = 'residual_boxes'
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
created_at: Mapped[datetime.datetime] = mapped_column(nullable=False)
|
||||
|
||||
pallet_id: Mapped[Optional[int]] = mapped_column(ForeignKey('residual_pallets.id'))
|
||||
pallet: Mapped[ResidualPallet] = relationship(back_populates='boxes')
|
||||
|
||||
client_id: Mapped[Optional[int]] = mapped_column(ForeignKey('clients.id'))
|
||||
client: Mapped['Client'] = relationship(back_populates='boxes')
|
||||
|
||||
residual_products: Mapped[list['ResidualProduct']] = relationship(back_populates='box')
|
||||
Reference in New Issue
Block a user