0.1.4 models update
This commit is contained in:
@@ -1,2 +1,4 @@
|
||||
from .files import Stored
|
||||
from .model import Model
|
||||
from .files import Stored, Markets
|
||||
from .model import Model
|
||||
from .goods import Nomenclature, DocumentTypes, Fabric
|
||||
from .accountant import AccountantSettings
|
||||
14
src/models/database_models/accountant.py
Normal file
14
src/models/database_models/accountant.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from src.models.database_models.model import Model
|
||||
from sqlalchemy import String
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from uuid import UUID, uuid1
|
||||
|
||||
class AccountantSettings(Model):
|
||||
__tablename__="accountant_settings"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
name:Mapped[str]=mapped_column(String(64),unique=True, index=True)
|
||||
database_key:Mapped[UUID]=mapped_column(default=uuid1, unique=True)
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'ID: {self.id}, Name: {self.name}'
|
||||
@@ -1,14 +1,43 @@
|
||||
from datetime import datetime
|
||||
from sqlalchemy import TIMESTAMP, String, func
|
||||
from sqlalchemy.orm import Mapped, mapped_column
|
||||
from sqlalchemy import TIMESTAMP, String, func, ForeignKey
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
from src.models.database_models.model import Model
|
||||
from uuid import UUID, uuid1
|
||||
|
||||
|
||||
class Stored(Model):
|
||||
__tablename__="reports"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
doc_id:Mapped[UUID]=mapped_column(default=uuid1, unique=True)
|
||||
filename:Mapped[str]=mapped_column(String(255), index=True)
|
||||
created_at:Mapped[datetime]=mapped_column(TIMESTAMP, server_default=func.now())
|
||||
uploaded_at:Mapped[datetime]=mapped_column(TIMESTAMP,onupdate=func.now(), nullable=True)
|
||||
doc_date:Mapped[datetime]=mapped_column(TIMESTAMP)
|
||||
status:Mapped[str]=mapped_column(String(64))
|
||||
user_id:Mapped[UUID]=mapped_column(ForeignKey("users.id", ondelete="CASCADE"), index=True)
|
||||
market_id:Mapped[int]=mapped_column(ForeignKey("markets.id", ondelete="CASCADE"),index=True)
|
||||
|
||||
|
||||
user:Mapped["User"]=relationship(back_populates="report")
|
||||
market:Mapped["Markets"]=relationship(back_populates="report")
|
||||
def __repr__(self) -> str:
|
||||
return f'ID: {self.id}, Filename: {self.filename}'
|
||||
return f'ID: {self.id}, Filename: {self.filename}, Status: {self.status}'
|
||||
|
||||
class Markets(Model):
|
||||
__tablename__="markets"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
name:Mapped[str]=mapped_column(String(64), unique=True)
|
||||
|
||||
report:Mapped[list["Stored"]]=relationship(back_populates="market")
|
||||
def __repr__(self) -> str:
|
||||
return f'ID: {self.id}, Name: {self.name}'
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
42
src/models/database_models/goods.py
Normal file
42
src/models/database_models/goods.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from decimal import Decimal
|
||||
from src.models.database_models.model import Model
|
||||
from sqlalchemy import Boolean, ForeignKey, Integer, Numeric, String
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
class Nomenclature(Model):
|
||||
__tablename__="goods"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
article:Mapped[str]=mapped_column(String(16), unique=True, index=True)
|
||||
price:Mapped[Decimal]=mapped_column(Numeric(10, 2), index=True)
|
||||
tnvd:Mapped[int]=mapped_column(Integer, index=True, unique=True)
|
||||
doc_type_id:Mapped[int]=mapped_column(ForeignKey("doc_types.id", ondelete="CASCADE"), index=True)
|
||||
fabric_id:Mapped[int]=mapped_column(ForeignKey("fabric.id", ondelete="CASCADE"), index=True)
|
||||
status:Mapped[bool]=mapped_column(Boolean)
|
||||
|
||||
doc_type:Mapped["DocumentTypes"]=relationship(back_populates="good")
|
||||
fabric:Mapped["Fabric"]=relationship(back_populates="good")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'ID: {self.id}, Article: {self.article}, Price: {self.price}'
|
||||
class DocumentTypes(Model):
|
||||
__tablename__="doc_types"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
name:Mapped[str]=mapped_column(String(64), unique=True, index=True)
|
||||
|
||||
good:Mapped[list["Nomenclature"]]=relationship(back_populates="doc_type")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f'ID: {self.id}, Name:{self.name}'
|
||||
|
||||
class Fabric(Model):
|
||||
__tablename__="fabric"
|
||||
|
||||
id:Mapped[int]=mapped_column(primary_key=True, index=True)
|
||||
name:Mapped[str]=mapped_column(String(64),unique=True, index=True)
|
||||
|
||||
|
||||
good:Mapped[list["Nomenclature"]]=relationship(back_populates="fabric")
|
||||
def __repr__(self) -> str:
|
||||
return f"ID: {self.id}, Name: {self.name}"
|
||||
@@ -30,6 +30,7 @@ class User(Model):
|
||||
direct_permissions:Mapped[list['Permissions']]=relationship(secondary="user_direct_permissions", back_populates="users_direct")
|
||||
|
||||
refresh_token:Mapped[list['RefreshTokens']]=relationship(back_populates="user")
|
||||
report:Mapped[list["Stored"]]=relationship(back_populates="user")
|
||||
def __repr__(self) -> str:
|
||||
return f"ID: {self.id}, Name: {self.first_name}, Status: {self.status}"
|
||||
|
||||
|
||||
9
src/models/pydantic_models/accountant.py
Normal file
9
src/models/pydantic_models/accountant.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from typing import Annotated
|
||||
from src.models.pydantic_models.model import Base
|
||||
from pydantic import Field
|
||||
from uuid import UUID
|
||||
class AccountantCreate(Base):
|
||||
|
||||
name:Annotated[str, Field(...,max_length=64,description="name of the accountant setting")]
|
||||
database_key:Annotated[UUID, Field(..., description="database key from the 1C server")]
|
||||
|
||||
26
src/models/pydantic_models/files.py
Normal file
26
src/models/pydantic_models/files.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from datetime import datetime
|
||||
from typing import Annotated
|
||||
from uuid import UUID
|
||||
from src.models.pydantic_models.model import Base
|
||||
from pydantic import Field
|
||||
|
||||
class ReportCreate(Base):
|
||||
filename:Annotated[str,Field(..., min_length=2, max_length=255, description="name of the report")]
|
||||
doc_date:Annotated[datetime, Field(..., description="ts of the report")]
|
||||
status:Annotated[str, Field(..., max_length=64, description="status of the report (uploaded,finalized, failed)")]
|
||||
user:Annotated[UUID, Field(..., description="id of the user author")]
|
||||
market:Annotated[str, Field(..., max_length=64,description="name of the market")]
|
||||
|
||||
class ReportOut(Base):
|
||||
filename:Annotated[str,Field(..., min_length=2, max_length=255, description="name of the report")]
|
||||
doc_date:Annotated[datetime, Field(..., description="ts of the report")]
|
||||
status:Annotated[str, Field(..., max_length=64, description="status of the report (uploaded,finalized, failed)")]
|
||||
user:Annotated[UUID, Field(..., description="id of the user author")]
|
||||
market:Annotated[str, Field(..., max_length=64, description="name of the market")]
|
||||
|
||||
|
||||
class MarketCreate(Base):
|
||||
name:Annotated[str, Field(..., max_length=64,description="certificate or declaration")]
|
||||
|
||||
class MarketOut(Base):
|
||||
name:Annotated[str, Field(..., max_length=64,description="certificate or declaration")]
|
||||
35
src/models/pydantic_models/goods.py
Normal file
35
src/models/pydantic_models/goods.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from decimal import Decimal
|
||||
from src.models.pydantic_models.model import Base
|
||||
from pydantic import Field
|
||||
from typing import Annotated
|
||||
|
||||
class NomenclatureCreate(Base):
|
||||
|
||||
article:Annotated[str, Field(...,min_length=5,max_length=16, description="name of the article")]
|
||||
price:Annotated[Decimal, Field(..., max_digits=12, description="price of the article")]
|
||||
tnvd:Annotated[int, Field(..., max_digits=10, description="tnvd from the Markirovka.crpt")]
|
||||
status:Annotated[bool, Field(..., description="status of the article")]
|
||||
|
||||
doc_type:Annotated[str, Field(..., description="document type (declaration or certificate)")]
|
||||
fabric:Annotated[str, Field(..., description="fabric of the product")]
|
||||
|
||||
class NomenclatureOut(Base):
|
||||
article:Annotated[str, Field(..., min_length=5,max_length=16, description="name of the article")]
|
||||
price:Annotated[Decimal, Field(..., max_digits=12,description="price of the article")]
|
||||
tnvd:Annotated[int, Field(..., max_digits=10,description="tnvd from the Markirovka.crpt")]
|
||||
status:Annotated[bool, Field(..., description="status of the article")]
|
||||
|
||||
doc_type:Annotated[str, Field(...,max_length=64, description="document type (declaration or certificate)")]
|
||||
fabric:Annotated[str, Field(...,max_length=64, description="fabric of the product")]
|
||||
|
||||
class DocumentTypeCreate(Base):
|
||||
name:Annotated[str, Field(...,max_length=64, description="certificate or declaration")]
|
||||
|
||||
class DocumentTypeOut(Base):
|
||||
name:Annotated[str, Field(..., max_length=64,description="certificate or declaration")]
|
||||
|
||||
class FabricCreate(Base):
|
||||
name:Annotated[str, Field(..., max_length=64,description="certificate or declaration")]
|
||||
|
||||
class FabricOut(Base):
|
||||
name:Annotated[str, Field(..., max_length=64,description="certificate or declaration")]
|
||||
@@ -40,8 +40,7 @@ class UserUpdate(Base):
|
||||
permissions:Annotated[list[str]|None, Field(None, description="permissions of the user")]
|
||||
permission_groups:Annotated[list[str]|None, Field(None, description="permissions groups of the user")]
|
||||
|
||||
class Permissions(Base):
|
||||
id:int
|
||||
class PermissionsCreate(Base):
|
||||
permission:Annotated[str, Field(..., max_length=30, description="permission name")]
|
||||
|
||||
|
||||
@@ -49,8 +48,8 @@ class PermissionsOut(Base):
|
||||
permission:Annotated[str, Field(..., max_length=30, description="permission name")]
|
||||
|
||||
|
||||
class PermissionsGroups(Base):
|
||||
id:int
|
||||
class PermissionsGroupsCreate(Base):
|
||||
|
||||
group:Annotated[str, Field(..., max_length=255, description="group name for the permissions")]
|
||||
|
||||
|
||||
@@ -59,21 +58,20 @@ class PermissionsGroupsOut(Base):
|
||||
group:Annotated[str, Field(..., max_length=255, description="group name for the permissions")]
|
||||
|
||||
|
||||
class RefreshTokens(Base):
|
||||
class RefreshTokensCreate(Base):
|
||||
|
||||
user_id:Annotated[UUID, Field(..., description="foreign key for the user")]
|
||||
token_hash:Annotated[str, Field(..., description="token hash")]
|
||||
device_info:Annotated[str, Field(..., description="User device info")]
|
||||
ip_address:Annotated[str, Field(..., description="ip v4/v6 of the user")]
|
||||
token_hash:Annotated[str, Field(...,max_length=255, description="token hash")]
|
||||
device_info:Annotated[str, Field(...,max_length=255, description="User device info")]
|
||||
ip_address:Annotated[str, Field(...,max_length=45, description="ip v4/v6 of the user")]
|
||||
is_revoked:Annotated[bool|None, Field(None, description="revoke token if logout was made")]
|
||||
expires_at:Annotated[datetime, Field(..., description="when token is going to be expired")]
|
||||
|
||||
class RefreshTokensOut(Base):
|
||||
|
||||
id:int
|
||||
|
||||
user_id:Annotated[UUID, Field(..., description="foreign key for the user")]
|
||||
token_hash:Annotated[str, Field(..., description="token hash")]
|
||||
device_info:Annotated[str, Field(..., description="User device info")]
|
||||
ip_address:Annotated[str, Field(..., description="ip v4/v6 of the user")]
|
||||
token_hash:Annotated[str, Field(..., max_length=255,description="token hash")]
|
||||
device_info:Annotated[str, Field(..., max_length=255, description="User device info")]
|
||||
ip_address:Annotated[str, Field(...,max_length=45, description="ip v4/v6 of the user")]
|
||||
is_revoked:Annotated[bool|None, Field(None, description="revoke token if logout was made")]
|
||||
expires_at:Annotated[datetime, Field(..., description="when token is going to be expired")]
|
||||
|
||||
Reference in New Issue
Block a user