feat: residues accounting
This commit is contained in:
@@ -14,5 +14,6 @@ from .billing import *
|
||||
from .marketplace_products import *
|
||||
from .deal_group import *
|
||||
from .transaction import *
|
||||
from .residues import *
|
||||
|
||||
configure_mappers()
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
from typing import Optional
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from sqlalchemy import Column, Integer, String, DateTime, ForeignKey
|
||||
from sqlalchemy.orm import relationship, Mapped, mapped_column
|
||||
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import ResidualPallet, ResidualBox
|
||||
|
||||
|
||||
class Client(BaseModel):
|
||||
__tablename__ = 'clients'
|
||||
@@ -28,6 +31,9 @@ class Client(BaseModel):
|
||||
|
||||
comment: Mapped[Optional[str]] = mapped_column(nullable=True, server_default=None, comment='Комментарий')
|
||||
|
||||
pallets: Mapped[list["ResidualPallet"]] = relationship(back_populates='client', lazy='selectin')
|
||||
boxes: Mapped[list["ResidualBox"]] = relationship(back_populates='client', lazy='selectin')
|
||||
|
||||
|
||||
class ClientDetails(BaseModel):
|
||||
__tablename__ = 'client_details'
|
||||
|
||||
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')
|
||||
@@ -5,7 +5,7 @@ from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from models import BaseModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from models import Deal, Product
|
||||
from models import Deal, Product, Client
|
||||
|
||||
|
||||
class Pallet(BaseModel):
|
||||
|
||||
Reference in New Issue
Block a user