lavkach3

Форк
0
90 строк · 4.4 Кб
1
from __future__ import annotations
2

3
from datetime import datetime
4
from typing import Optional, List, TYPE_CHECKING
5

6
from celery.worker.strategy import default
7
from fastapi_filter.contrib.sqlalchemy import Filter
8
from pydantic import BaseModel, computed_field
9
from pydantic.types import UUID4
10
from core.schemas.basic_schemes import BasicField as Field, ActionBaseSchame
11

12
from app.inventory.order.enums.order_enum import OrderStatus
13
from app.inventory.order.models import Order
14
from app.inventory.order.schemas.order_type_schemas import OrderTypeScheme
15
from core.schemas import BaseFilter
16
from core.schemas.basic_schemes import BasicModel
17
from core.schemas.list_schema import GenericListSchema
18
from core.schemas.timestamps import TimeStampScheme
19
from core.types import UUID
20
from app.inventory.order.schemas.move_schemas import MoveScheme, MoveCreateScheme,MoveUpdateScheme
21

22

23
class OrderBaseScheme(BasicModel):
24
    external_number: Optional[str] = Field(default=None, title='External ID', table=True, form=True)
25
    order_type_id: UUID = Field(title='Order type', model='order_type')
26
    store_id: UUID = Field(title='Store', table=True, form=True, model='store')
27
    partner_id: Optional[UUID] = Field(default=None, title='Partner', table=True, form=True, model='partner', readonly=True)
28
    lot_id: Optional[UUID] = Field(default=None, title='Lot', model='lot')
29
    origin_type: Optional[str] = Field(default=None, title='Original Type', form=True)
30
    origin_number: Optional[str] = Field(default=None, title='Original', table=True, form=True)
31
    planned_datetime: Optional[datetime] = Field(default=None, title='Planned Date', table=True)
32
    expiration_datetime: Optional[datetime] = Field(default=None, title='Expiration Date', table=True)
33
    description: Optional[str] = Field(default=None, title='Description', table=True)
34
    status: OrderStatus = Field(default=OrderStatus.DRAFT, title='Status', readonly=True, table=True)
35
    order_id: Optional[UUID] = Field(default=None, title='Parent', readonly=True)
36

37

38
    class Config:
39
        orm_model = Order
40
        readonly = [('status', '==', 'draft')]            # Переопределяет readonly для всех полей модели для UI
41

42

43

44
class OrderUpdateScheme(OrderBaseScheme):
45
    move_list_rel: Optional[list['MoveUpdateScheme']] = Field(default=[], title='Order Movements')
46
    order_type_id: Optional[UUID] = Field(default=None, title='Order type', model='order_type', readonly=True, filter={'status__in': OrderStatus.DRAFT.value})
47

48

49
class OrderCreateScheme(OrderBaseScheme):
50
    move_list_rel: Optional[list[MoveCreateScheme]] = Field(default=[], title='Order Movements')
51

52

53
class OrderScheme(OrderCreateScheme, TimeStampScheme):
54
    lsn: int = Field(title='LSN', readonly=True)
55
    id: UUID4 = Field(title='ID', table=True, readonly=True)
56
    company_id: UUID = Field(title='Company', model='company')
57
    vars: Optional[dict] = None
58
    number: str = Field(title='Order #', readonly=True, description="Internal number of order")
59
    actual_datetime: Optional[datetime] = Field(title='Actual Date')
60
    created_by: UUID = Field(title='Created By',  model='user')
61
    edited_by: UUID = Field(title='Edit By', model='user')
62
    user_ids: Optional[list[UUID]] = Field(default=[], title='Users', readonly=True, model='user')
63
    order_type_rel: OrderTypeScheme = Field(title='Order Type', table=True, form=True, readonly=True)
64
    move_list_rel: Optional[list["MoveScheme"]] = Field(default=[], title='Order Movements')
65

66
    @computed_field(title='Order #', json_schema_extra={'table': True})
67
    def title(self) -> str:
68
        "some title"
69
        return f'{self.number}'
70

71

72
class OrderFilter(BaseFilter):
73
    planned_datetime__gte: Optional[datetime] = Field(title="bigger or equal planned date", default=None)
74
    planned_datetime__lt: Optional[datetime] = Field(title="less planned date", default=None)
75
    status__in: Optional[List[OrderStatus]] = Field(default=None, title='Order Status')
76
    store_id__in: Optional[List[UUID]] = Field(default=None, title='Store', model='store')
77
    order_type_id__in: Optional[List[UUID]] = Field(default=None, title='Order Type', model='order_type')
78

79
    class Constants(Filter.Constants):
80
        model = Order
81
        ordering_field_name = "order_by"
82
        search_model_fields = ["external_number", "origin_number", "number"]
83

84

85
class OrderListSchema(GenericListSchema):
86
    data: Optional[List[OrderScheme]]
87

88

89
class AssignUser(ActionBaseSchame):
90
    user_id: Optional[UUID] = Field(default=None, title='User')
91

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.