feat: warehouse places accounting
This commit is contained in:
5
models_wms/__init__.py
Normal file
5
models_wms/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from sqlalchemy.orm import configure_mappers
|
||||
|
||||
from .place import *
|
||||
|
||||
configure_mappers()
|
||||
12
models_wms/base.py
Normal file
12
models_wms/base.py
Normal file
@@ -0,0 +1,12 @@
|
||||
from sqlalchemy.ext.asyncio import AsyncAttrs
|
||||
from sqlalchemy.orm import declarative_base, DeclarativeBase
|
||||
|
||||
|
||||
class BaseModel(DeclarativeBase, AsyncAttrs):
|
||||
def __repr__(self):
|
||||
if hasattr(self, 'id'):
|
||||
return f'<{self.__class__.__name__} id={self.id}>'
|
||||
return super().__repr__()
|
||||
|
||||
|
||||
metadata = BaseModel.metadata
|
||||
60
models_wms/place.py
Normal file
60
models_wms/place.py
Normal file
@@ -0,0 +1,60 @@
|
||||
from sqlalchemy import ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from models_wms.base import BaseModel
|
||||
|
||||
|
||||
class PlaceType(BaseModel):
|
||||
__tablename__ = 'place_type'
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
name: Mapped[str] = mapped_column(nullable=False)
|
||||
parent_id: Mapped[int] = mapped_column(
|
||||
ForeignKey('place_type.id'),
|
||||
nullable=True,
|
||||
)
|
||||
parent: Mapped['PlaceType'] = relationship(
|
||||
'PlaceType',
|
||||
lazy='noload',
|
||||
back_populates='children',
|
||||
primaryjoin='PlaceType.parent_id == PlaceType.id',
|
||||
remote_side=[id],
|
||||
)
|
||||
children: Mapped[list['PlaceType']] = relationship(
|
||||
'PlaceType',
|
||||
lazy='selectin',
|
||||
back_populates='parent',
|
||||
)
|
||||
|
||||
|
||||
class Place(BaseModel):
|
||||
__tablename__ = 'place'
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
number: Mapped[int] = mapped_column(nullable=False)
|
||||
|
||||
place_type_id: Mapped[int] = mapped_column(
|
||||
ForeignKey('place_type.id'),
|
||||
nullable=False,
|
||||
)
|
||||
place_type: Mapped[PlaceType] = relationship(
|
||||
'PlaceType',
|
||||
lazy='joined',
|
||||
)
|
||||
|
||||
parent_id: Mapped[int] = mapped_column(
|
||||
ForeignKey('place.id'),
|
||||
nullable=True,
|
||||
)
|
||||
parent: Mapped['Place'] = relationship(
|
||||
'Place',
|
||||
lazy='noload',
|
||||
back_populates='children',
|
||||
primaryjoin='Place.parent_id == Place.id',
|
||||
remote_side=[id],
|
||||
)
|
||||
children: Mapped[list['Place']] = relationship(
|
||||
'Place',
|
||||
lazy='selectin',
|
||||
back_populates='parent',
|
||||
)
|
||||
Reference in New Issue
Block a user